summaryrefslogtreecommitdiff
path: root/src/test/perl/PostgreSQL/Test/Utils.pm
diff options
context:
space:
mode:
authorDaniel Gustafsson <dgustafsson@postgresql.org>2022-02-23 14:22:16 +0100
committerDaniel Gustafsson <dgustafsson@postgresql.org>2022-02-23 14:22:16 +0100
commit6da65a3f9a9deae4fdcc768c612b0c8f52759f75 (patch)
treecad91d0d94ec95e4e7f63884952bcef13f8a4334 /src/test/perl/PostgreSQL/Test/Utils.pm
parent91d3580535238abf93c67a6d3dce64f0e8c3cc6d (diff)
Add function to pump IPC process until string match
Refactor the recovery tests to not carry a local duplicated copy of the pump_until function which pumps a process until a defined string is seen on a stream. This reduces duplication, and is in preparation for another patch which will also use this functionality. Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion https://postgr.es/m/YgynUafCyIu3jIhC@paquier.xyz
Diffstat (limited to 'src/test/perl/PostgreSQL/Test/Utils.pm')
-rw-r--r--src/test/perl/PostgreSQL/Test/Utils.pm23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/perl/PostgreSQL/Test/Utils.pm b/src/test/perl/PostgreSQL/Test/Utils.pm
index 2c0c72f57ac..46cd7467963 100644
--- a/src/test/perl/PostgreSQL/Test/Utils.pm
+++ b/src/test/perl/PostgreSQL/Test/Utils.pm
@@ -73,6 +73,7 @@ our @EXPORT = qw(
system_log
run_log
run_command
+ pump_until
command_ok
command_fails
@@ -408,6 +409,28 @@ sub run_command
=pod
+=item pump_until(proc, timeout, stream, until)
+
+Pump until string is matched on the specified stream, or timeout occurs.
+
+=cut
+
+sub pump_until
+{
+ my ($proc, $timeout, $stream, $until) = @_;
+ $proc->pump_nb();
+ while (1)
+ {
+ last if $$stream =~ /$until/;
+ return 0 if ($timeout->is_expired);
+ return 0 if (not $proc->pumpable());
+ $proc->pump();
+ }
+ return 1;
+}
+
+=pod
+
=item generate_ascii_string(from_char, to_char)
Generate a string made of the given range of ASCII characters.