File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ our @EXPORT = qw(
2525 system_or_bail
2626 system_log
2727 run_log
28+ pump_until
2829
2930 command_ok
3031 command_fails
Original file line number Diff line number Diff line change @@ -2065,6 +2065,41 @@ sub wait_for_slot_catchup
20652065
20662066=pod
20672067
2068+ =item $node->wait_for_log(regexp, offset)
2069+
2070+ Waits for the contents of the server log file, starting at the given offset, to
2071+ match the supplied regular expression. Checks the entire log if no offset is
2072+ given. Times out after $TestLib::timeout_default seconds.
2073+
2074+ If successful, returns the length of the entire log file, in bytes.
2075+
2076+ =cut
2077+
2078+ sub wait_for_log
2079+ {
2080+ my ($self , $regexp , $offset ) = @_ ;
2081+ $offset = 0 unless defined $offset ;
2082+
2083+ my $max_attempts = 10 * $TestLib::timeout_default ;
2084+ my $attempts = 0;
2085+
2086+ while ($attempts < $max_attempts )
2087+ {
2088+ my $log = TestLib::slurp_file($self -> logfile, $offset );
2089+
2090+ return $offset +length ($log ) if ($log =~ m /$regexp / );
2091+
2092+ # Wait 0.1 second before retrying.
2093+ usleep(100_000);
2094+
2095+ $attempts ++;
2096+ }
2097+
2098+ croak " timed out waiting for match: $regexp " ;
2099+ }
2100+
2101+ =pod
2102+
20682103=item $node->query_hash($dbname, $query, @columns)
20692104
20702105Execute $query on $dbname, replacing any appearance of the string __COLUMNS__
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ our @EXPORT = qw(
3636 system_or_bail
3737 system_log
3838 run_log
39+ pump_until
3940
4041 command_ok
4142 command_fails
@@ -238,6 +239,36 @@ sub run_log
238239 return IPC::Run::run(@_ );
239240}
240241
242+ =pod
243+
244+ =item pump_until(proc, timeout, stream, until)
245+
246+ Pump until string is matched on the specified stream, or timeout occurs.
247+
248+ =cut
249+
250+ sub pump_until
251+ {
252+ my ($proc , $timeout , $stream , $until ) = @_ ;
253+ $proc -> pump_nb();
254+ while (1)
255+ {
256+ last if $$stream =~ / $until / ;
257+ if ($timeout -> is_expired)
258+ {
259+ diag(" pump_until: timeout expired when searching for \" $until \" with stream: \" $$stream \" " );
260+ return 0;
261+ }
262+ if (not $proc -> pumpable())
263+ {
264+ diag(" pump_until: process terminated unexpectedly when searching for \" $until \" with stream: \" $$stream \" " );
265+ return 0;
266+ }
267+ $proc -> pump();
268+ }
269+ return 1;
270+ }
271+
241272# Generate a string made of the given range of ASCII characters
242273sub generate_ascii_string
243274{
You can’t perform that action at this time.
0 commit comments