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 @@ -26,6 +26,7 @@ our @EXPORT = qw(
2626 system_log
2727 run_log
2828 run_command
29+ pump_until
2930
3031 command_ok
3132 command_fails
Original file line number Diff line number Diff line change @@ -2184,6 +2184,41 @@ sub wait_for_slot_catchup
21842184
21852185=pod
21862186
2187+ =item $node->wait_for_log(regexp, offset)
2188+
2189+ Waits for the contents of the server log file, starting at the given offset, to
2190+ match the supplied regular expression. Checks the entire log if no offset is
2191+ given. Times out after $TestLib::timeout_default seconds.
2192+
2193+ If successful, returns the length of the entire log file, in bytes.
2194+
2195+ =cut
2196+
2197+ sub wait_for_log
2198+ {
2199+ my ($self , $regexp , $offset ) = @_ ;
2200+ $offset = 0 unless defined $offset ;
2201+
2202+ my $max_attempts = 10 * $TestLib::timeout_default ;
2203+ my $attempts = 0;
2204+
2205+ while ($attempts < $max_attempts )
2206+ {
2207+ my $log = TestLib::slurp_file($self -> logfile, $offset );
2208+
2209+ return $offset +length ($log ) if ($log =~ m /$regexp / );
2210+
2211+ # Wait 0.1 second before retrying.
2212+ usleep(100_000);
2213+
2214+ $attempts ++;
2215+ }
2216+
2217+ croak " timed out waiting for match: $regexp " ;
2218+ }
2219+
2220+ =pod
2221+
21872222=item $node->query_hash($dbname, $query, @columns)
21882223
21892224Execute $query on $dbname, replacing any appearance of the string __COLUMNS__
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ our @EXPORT = qw(
7070 system_log
7171 run_log
7272 run_command
73+ pump_until
7374
7475 command_ok
7576 command_fails
@@ -377,6 +378,36 @@ sub run_command
377378
378379=pod
379380
381+ =item pump_until(proc, timeout, stream, until)
382+
383+ Pump until string is matched on the specified stream, or timeout occurs.
384+
385+ =cut
386+
387+ sub pump_until
388+ {
389+ my ($proc , $timeout , $stream , $until ) = @_ ;
390+ $proc -> pump_nb();
391+ while (1)
392+ {
393+ last if $$stream =~ / $until / ;
394+ if ($timeout -> is_expired)
395+ {
396+ diag(" pump_until: timeout expired when searching for \" $until \" with stream: \" $$stream \" " );
397+ return 0;
398+ }
399+ if (not $proc -> pumpable())
400+ {
401+ diag(" pump_until: process terminated unexpectedly when searching for \" $until \" with stream: \" $$stream \" " );
402+ return 0;
403+ }
404+ $proc -> pump();
405+ }
406+ return 1;
407+ }
408+
409+ =pod
410+
380411=item generate_ascii_string(from_char, to_char)
381412
382413Generate a string made of the given range of ASCII characters.
You can’t perform that action at this time.
0 commit comments