File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ our @EXPORT = qw(
22
22
system_or_bail
23
23
system_log
24
24
run_log
25
+ pump_until
25
26
26
27
command_ok
27
28
command_fails
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ package PostgresNode;
83
83
use strict;
84
84
use warnings;
85
85
86
+ use Carp;
86
87
use Config;
87
88
use Cwd;
88
89
use Exporter ' import' ;
@@ -1932,6 +1933,41 @@ qq[SELECT '$target_lsn' <= ${mode}_lsn FROM pg_catalog.pg_replication_slots WHER
1932
1933
1933
1934
=pod
1934
1935
1936
+ =item $node->wait_for_log(regexp, offset)
1937
+
1938
+ Waits for the contents of the server log file, starting at the given offset, to
1939
+ match the supplied regular expression. Checks the entire log if no offset is
1940
+ given. Times out after $TestLib::timeout_default seconds.
1941
+
1942
+ If successful, returns the length of the entire log file, in bytes.
1943
+
1944
+ =cut
1945
+
1946
+ sub wait_for_log
1947
+ {
1948
+ my ($self , $regexp , $offset ) = @_ ;
1949
+ $offset = 0 unless defined $offset ;
1950
+
1951
+ my $max_attempts = 10 * $TestLib::timeout_default ;
1952
+ my $attempts = 0;
1953
+
1954
+ while ($attempts < $max_attempts )
1955
+ {
1956
+ my $log = TestLib::slurp_file($self -> logfile, $offset );
1957
+
1958
+ return $offset +length ($log ) if ($log =~ m /$regexp / );
1959
+
1960
+ # Wait 0.1 second before retrying.
1961
+ usleep(100_000);
1962
+
1963
+ $attempts ++;
1964
+ }
1965
+
1966
+ croak " timed out waiting for match: $regexp " ;
1967
+ }
1968
+
1969
+ =pod
1970
+
1935
1971
=item $node->query_hash($dbname, $query, @columns)
1936
1972
1937
1973
Execute $query on $dbname, replacing any appearance of the string __COLUMNS__
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ our @EXPORT = qw(
31
31
system_or_bail
32
32
system_log
33
33
run_log
34
+ pump_until
34
35
35
36
command_ok
36
37
command_fails
@@ -232,6 +233,36 @@ sub run_log
232
233
return IPC::Run::run(@_ );
233
234
}
234
235
236
+ =pod
237
+
238
+ =item pump_until(proc, timeout, stream, until)
239
+
240
+ Pump until string is matched on the specified stream, or timeout occurs.
241
+
242
+ =cut
243
+
244
+ sub pump_until
245
+ {
246
+ my ($proc , $timeout , $stream , $until ) = @_ ;
247
+ $proc -> pump_nb();
248
+ while (1)
249
+ {
250
+ last if $$stream =~ / $until / ;
251
+ if ($timeout -> is_expired)
252
+ {
253
+ diag(" pump_until: timeout expired when searching for \" $until \" with stream: \" $$stream \" " );
254
+ return 0;
255
+ }
256
+ if (not $proc -> pumpable())
257
+ {
258
+ diag(" pump_until: process terminated unexpectedly when searching for \" $until \" with stream: \" $$stream \" " );
259
+ return 0;
260
+ }
261
+ $proc -> pump();
262
+ }
263
+ return 1;
264
+ }
265
+
235
266
# Generate a string made of the given range of ASCII characters
236
267
sub generate_ascii_string
237
268
{
You can’t perform that action at this time.
0 commit comments