mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
Add function to pump IPC process until string match
Refactor the recovery tests to not carry a local duplicated copy of the pump_until function which pumps a process until a defined string is seen on a stream. This reduces duplication, and is in preparation for another patch which will also use this functionality. Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion https://postgr.es/m/YgynUafCyIu3jIhC@paquier.xyz
This commit is contained in:
parent
91d3580535
commit
6da65a3f9a
@ -73,6 +73,7 @@ our @EXPORT = qw(
|
||||
system_log
|
||||
run_log
|
||||
run_command
|
||||
pump_until
|
||||
|
||||
command_ok
|
||||
command_fails
|
||||
@ -408,6 +409,28 @@ sub run_command
|
||||
|
||||
=pod
|
||||
|
||||
=item pump_until(proc, timeout, stream, until)
|
||||
|
||||
Pump until string is matched on the specified stream, or timeout occurs.
|
||||
|
||||
=cut
|
||||
|
||||
sub pump_until
|
||||
{
|
||||
my ($proc, $timeout, $stream, $until) = @_;
|
||||
$proc->pump_nb();
|
||||
while (1)
|
||||
{
|
||||
last if $$stream =~ /$until/;
|
||||
return 0 if ($timeout->is_expired);
|
||||
return 0 if (not $proc->pumpable());
|
||||
$proc->pump();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
=pod
|
||||
|
||||
=item generate_ascii_string(from_char, to_char)
|
||||
|
||||
Generate a string made of the given range of ASCII characters.
|
||||
|
@ -71,7 +71,7 @@ CREATE TABLE alive(status text);
|
||||
INSERT INTO alive VALUES($$committed-before-sigquit$$);
|
||||
SELECT pg_backend_pid();
|
||||
];
|
||||
ok(pump_until($killme, \$killme_stdout, qr/[[:digit:]]+[\r\n]$/m),
|
||||
ok(pump_until($killme, $psql_timeout, \$killme_stdout, qr/[[:digit:]]+[\r\n]$/m),
|
||||
'acquired pid for SIGQUIT');
|
||||
my $pid = $killme_stdout;
|
||||
chomp($pid);
|
||||
@ -83,7 +83,7 @@ $killme_stdin .= q[
|
||||
BEGIN;
|
||||
INSERT INTO alive VALUES($$in-progress-before-sigquit$$) RETURNING status;
|
||||
];
|
||||
ok(pump_until($killme, \$killme_stdout, qr/in-progress-before-sigquit/m),
|
||||
ok(pump_until($killme, $psql_timeout, \$killme_stdout, qr/in-progress-before-sigquit/m),
|
||||
'inserted in-progress-before-sigquit');
|
||||
$killme_stdout = '';
|
||||
$killme_stderr = '';
|
||||
@ -96,7 +96,7 @@ $monitor_stdin .= q[
|
||||
SELECT $$psql-connected$$;
|
||||
SELECT pg_sleep(3600);
|
||||
];
|
||||
ok(pump_until($monitor, \$monitor_stdout, qr/psql-connected/m),
|
||||
ok(pump_until($monitor, $psql_timeout, \$monitor_stdout, qr/psql-connected/m),
|
||||
'monitor connected');
|
||||
$monitor_stdout = '';
|
||||
$monitor_stderr = '';
|
||||
@ -113,6 +113,7 @@ SELECT 1;
|
||||
];
|
||||
ok( pump_until(
|
||||
$killme,
|
||||
$psql_timeout,
|
||||
\$killme_stderr,
|
||||
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
|
||||
),
|
||||
@ -126,6 +127,7 @@ $killme->finish;
|
||||
# sending.
|
||||
ok( pump_until(
|
||||
$monitor,
|
||||
$psql_timeout,
|
||||
\$monitor_stderr,
|
||||
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
|
||||
),
|
||||
@ -148,7 +150,7 @@ $monitor->run();
|
||||
$killme_stdin .= q[
|
||||
SELECT pg_backend_pid();
|
||||
];
|
||||
ok(pump_until($killme, \$killme_stdout, qr/[[:digit:]]+[\r\n]$/m),
|
||||
ok(pump_until($killme, $psql_timeout, \$killme_stdout, qr/[[:digit:]]+[\r\n]$/m),
|
||||
"acquired pid for SIGKILL");
|
||||
$pid = $killme_stdout;
|
||||
chomp($pid);
|
||||
@ -161,7 +163,7 @@ INSERT INTO alive VALUES($$committed-before-sigkill$$) RETURNING status;
|
||||
BEGIN;
|
||||
INSERT INTO alive VALUES($$in-progress-before-sigkill$$) RETURNING status;
|
||||
];
|
||||
ok(pump_until($killme, \$killme_stdout, qr/in-progress-before-sigkill/m),
|
||||
ok(pump_until($killme, $psql_timeout, \$killme_stdout, qr/in-progress-before-sigkill/m),
|
||||
'inserted in-progress-before-sigkill');
|
||||
$killme_stdout = '';
|
||||
$killme_stderr = '';
|
||||
@ -173,7 +175,7 @@ $monitor_stdin .= q[
|
||||
SELECT $$psql-connected$$;
|
||||
SELECT pg_sleep(3600);
|
||||
];
|
||||
ok(pump_until($monitor, \$monitor_stdout, qr/psql-connected/m),
|
||||
ok(pump_until($monitor, $psql_timeout, \$monitor_stdout, qr/psql-connected/m),
|
||||
'monitor connected');
|
||||
$monitor_stdout = '';
|
||||
$monitor_stderr = '';
|
||||
@ -191,6 +193,7 @@ SELECT 1;
|
||||
];
|
||||
ok( pump_until(
|
||||
$killme,
|
||||
$psql_timeout,
|
||||
\$killme_stderr,
|
||||
qr/server closed the connection unexpectedly|connection to server was lost/m
|
||||
),
|
||||
@ -202,6 +205,7 @@ $killme->finish;
|
||||
# sending.
|
||||
ok( pump_until(
|
||||
$monitor,
|
||||
$psql_timeout,
|
||||
\$monitor_stderr,
|
||||
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
|
||||
),
|
||||
@ -240,34 +244,4 @@ is( $node->safe_psql(
|
||||
|
||||
$node->stop();
|
||||
|
||||
# Pump until string is matched, or timeout occurs
|
||||
sub pump_until
|
||||
{
|
||||
my ($proc, $stream, $untl) = @_;
|
||||
$proc->pump_nb();
|
||||
while (1)
|
||||
{
|
||||
last if $$stream =~ /$untl/;
|
||||
if ($psql_timeout->is_expired)
|
||||
{
|
||||
diag("aborting wait: program timed out");
|
||||
diag("stream contents: >>", $$stream, "<<");
|
||||
diag("pattern searched for: ", $untl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
if (not $proc->pumpable())
|
||||
{
|
||||
diag("aborting wait: program died");
|
||||
diag("stream contents: >>", $$stream, "<<");
|
||||
diag("pattern searched for: ", $untl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
$proc->pump();
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
done_testing();
|
||||
|
@ -57,7 +57,7 @@ my $killme = IPC::Run::start(
|
||||
$killme_stdin .= q[
|
||||
SELECT pg_backend_pid();
|
||||
];
|
||||
ok(pump_until($killme, \$killme_stdout, qr/[[:digit:]]+[\r\n]$/m),
|
||||
ok(pump_until($killme, $psql_timeout, \$killme_stdout, qr/[[:digit:]]+[\r\n]$/m),
|
||||
'acquired pid for SIGKILL');
|
||||
my $pid = $killme_stdout;
|
||||
chomp($pid);
|
||||
@ -86,7 +86,7 @@ BEGIN;
|
||||
INSERT INTO tab_crash (a) VALUES(1);
|
||||
SELECT $$insert-tuple-to-lock-next-insert$$;
|
||||
];
|
||||
pump_until($killme2, \$killme_stdout2, qr/insert-tuple-to-lock-next-insert/m);
|
||||
pump_until($killme2, $psql_timeout, \$killme_stdout2, qr/insert-tuple-to-lock-next-insert/m);
|
||||
$killme_stdout2 = '';
|
||||
$killme_stderr2 = '';
|
||||
|
||||
@ -99,7 +99,7 @@ BEGIN;
|
||||
SELECT $$in-progress-before-sigkill$$;
|
||||
INSERT INTO tab_crash (a) SELECT i FROM generate_series(1, 5000) s(i);
|
||||
];
|
||||
ok(pump_until($killme, \$killme_stdout, qr/in-progress-before-sigkill/m),
|
||||
ok(pump_until($killme, $psql_timeout, \$killme_stdout, qr/in-progress-before-sigkill/m),
|
||||
'insert in-progress-before-sigkill');
|
||||
$killme_stdout = '';
|
||||
$killme_stderr = '';
|
||||
@ -121,7 +121,7 @@ END; $c$;
|
||||
SELECT $$insert-tuple-lock-waiting$$;
|
||||
];
|
||||
|
||||
pump_until($killme2, \$killme_stdout2, qr/insert-tuple-lock-waiting/m);
|
||||
pump_until($killme2, $psql_timeout, \$killme_stdout2, qr/insert-tuple-lock-waiting/m);
|
||||
$killme_stdout2 = '';
|
||||
$killme_stderr2 = '';
|
||||
|
||||
@ -158,7 +158,7 @@ $killme->run();
|
||||
$killme_stdin .= q[
|
||||
SELECT pg_backend_pid();
|
||||
];
|
||||
ok(pump_until($killme, \$killme_stdout, qr/[[:digit:]]+[\r\n]$/m),
|
||||
ok(pump_until($killme, $psql_timeout, \$killme_stdout, qr/[[:digit:]]+[\r\n]$/m),
|
||||
'acquired pid for SIGKILL');
|
||||
$pid = $killme_stdout;
|
||||
chomp($pid);
|
||||
@ -175,7 +175,7 @@ BEGIN;
|
||||
INSERT INTO tab_crash (a) VALUES(1);
|
||||
SELECT $$insert-tuple-to-lock-next-insert$$;
|
||||
];
|
||||
pump_until($killme2, \$killme_stdout2, qr/insert-tuple-to-lock-next-insert/m);
|
||||
pump_until($killme2, $psql_timeout, \$killme_stdout2, qr/insert-tuple-to-lock-next-insert/m);
|
||||
$killme_stdout2 = '';
|
||||
$killme_stderr2 = '';
|
||||
|
||||
@ -188,7 +188,7 @@ BEGIN;
|
||||
SELECT $$in-progress-before-sigkill$$;
|
||||
INSERT INTO tab_crash (a) SELECT i FROM generate_series(1, 5000) s(i);
|
||||
];
|
||||
ok(pump_until($killme, \$killme_stdout, qr/in-progress-before-sigkill/m),
|
||||
ok(pump_until($killme, $psql_timeout, \$killme_stdout, qr/in-progress-before-sigkill/m),
|
||||
'insert in-progress-before-sigkill');
|
||||
$killme_stdout = '';
|
||||
$killme_stderr = '';
|
||||
@ -210,7 +210,7 @@ END; $c$;
|
||||
SELECT $$insert-tuple-lock-waiting$$;
|
||||
];
|
||||
|
||||
pump_until($killme2, \$killme_stdout2, qr/insert-tuple-lock-waiting/m);
|
||||
pump_until($killme2, $psql_timeout, \$killme_stdout2, qr/insert-tuple-lock-waiting/m);
|
||||
$killme_stdout2 = '';
|
||||
$killme_stderr2 = '';
|
||||
|
||||
@ -242,33 +242,4 @@ is( $node->safe_psql(
|
||||
|
||||
$node->stop();
|
||||
|
||||
# Pump until string is matched, or timeout occurs
|
||||
sub pump_until
|
||||
{
|
||||
my ($proc, $stream, $untl) = @_;
|
||||
$proc->pump_nb();
|
||||
while (1)
|
||||
{
|
||||
last if $$stream =~ /$untl/;
|
||||
if ($psql_timeout->is_expired)
|
||||
{
|
||||
diag("aborting wait: program timed out");
|
||||
diag("stream contents: >>", $$stream, "<<");
|
||||
diag("pattern searched for: ", $untl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
if (not $proc->pumpable())
|
||||
{
|
||||
diag("aborting wait: program died");
|
||||
diag("stream contents: >>", $$stream, "<<");
|
||||
diag("pattern searched for: ", $untl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
$proc->pump();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
done_testing();
|
||||
|
Loading…
x
Reference in New Issue
Block a user