Skip to content

Commit 5ab8e80

Browse files
committed
Backpatch addition of wait_for_log(), pump_until().
These were originally introduced in a2ab9c0 and a2ab9c0, as they are needed by a about-to-be-backpatched test. Discussion: https://postgr.es/m/20220413002626.udl7lll7f3o7nre7@alap3.anarazel.de Backpatch: 10-14
1 parent 24c58f7 commit 5ab8e80

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

src/test/perl/PostgreSQL/Test/Utils.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ our @EXPORT = qw(
2727
system_log
2828
run_log
2929
run_command
30+
pump_until
3031
3132
command_ok
3233
command_fails

src/test/perl/PostgresNode.pm

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,6 +2561,41 @@ sub wait_for_slot_catchup
25612561

25622562
=pod
25632563
2564+
=item $node->wait_for_log(regexp, offset)
2565+
2566+
Waits for the contents of the server log file, starting at the given offset, to
2567+
match the supplied regular expression. Checks the entire log if no offset is
2568+
given. Times out after $TestLib::timeout_default seconds.
2569+
2570+
If successful, returns the length of the entire log file, in bytes.
2571+
2572+
=cut
2573+
2574+
sub wait_for_log
2575+
{
2576+
my ($self, $regexp, $offset) = @_;
2577+
$offset = 0 unless defined $offset;
2578+
2579+
my $max_attempts = 10 * $TestLib::timeout_default;
2580+
my $attempts = 0;
2581+
2582+
while ($attempts < $max_attempts)
2583+
{
2584+
my $log = TestLib::slurp_file($self->logfile, $offset);
2585+
2586+
return $offset+length($log) if ($log =~ m/$regexp/);
2587+
2588+
# Wait 0.1 second before retrying.
2589+
usleep(100_000);
2590+
2591+
$attempts++;
2592+
}
2593+
2594+
croak "timed out waiting for match: $regexp";
2595+
}
2596+
2597+
=pod
2598+
25642599
=item $node->query_hash($dbname, $query, @columns)
25652600
25662601
Execute $query on $dbname, replacing any appearance of the string __COLUMNS__

src/test/perl/TestLib.pm

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ our @EXPORT = qw(
7474
system_log
7575
run_log
7676
run_command
77+
pump_until
7778
7879
command_ok
7980
command_fails
@@ -393,6 +394,36 @@ sub run_command
393394

394395
=pod
395396
397+
=item pump_until(proc, timeout, stream, until)
398+
399+
Pump until string is matched on the specified stream, or timeout occurs.
400+
401+
=cut
402+
403+
sub pump_until
404+
{
405+
my ($proc, $timeout, $stream, $until) = @_;
406+
$proc->pump_nb();
407+
while (1)
408+
{
409+
last if $$stream =~ /$until/;
410+
if ($timeout->is_expired)
411+
{
412+
diag("pump_until: timeout expired when searching for \"$until\" with stream: \"$$stream\"");
413+
return 0;
414+
}
415+
if (not $proc->pumpable())
416+
{
417+
diag("pump_until: process terminated unexpectedly when searching for \"$until\" with stream: \"$$stream\"");
418+
return 0;
419+
}
420+
$proc->pump();
421+
}
422+
return 1;
423+
}
424+
425+
=pod
426+
396427
=item generate_ascii_string(from_char, to_char)
397428
398429
Generate a string made of the given range of ASCII characters.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy