Skip to content

Commit 90abe1e

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 d85f2bf commit 90abe1e

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
@@ -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

src/test/perl/PostgresNode.pm

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff 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
21892224
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
@@ -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
382413
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