mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Move pump_until to TestLib.pm.
The subroutine pump_until provides the functionality to poll until the given string is matched, or a timeout occurs. This can be used from other places as well, so moving it to TestLib.pm. The immediate need is for an upcoming regression test patch for dropdb utility. Author: Vignesh C Reviewed-by: Amit Kapila Discussion: https://postgr.es/m/CAP_rwwmLJJbn70vLOZFpxGw3XD7nLB_7+NKz46H5EOO2k5H7OQ@mail.gmail.com
This commit is contained in:
@ -860,6 +860,43 @@ sub command_checks_all
|
|||||||
|
|
||||||
=pod
|
=pod
|
||||||
|
|
||||||
|
=item pump_until(proc, timeout, stream, untl)
|
||||||
|
|
||||||
|
# Pump until string is matched, or timeout occurs
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub pump_until
|
||||||
|
{
|
||||||
|
my ($proc, $timeout, $stream, $untl) = @_;
|
||||||
|
$proc->pump_nb();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
last if $$stream =~ /$untl/;
|
||||||
|
if ($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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
=pod
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
@ -72,7 +72,9 @@ CREATE TABLE alive(status text);
|
|||||||
INSERT INTO alive VALUES($$committed-before-sigquit$$);
|
INSERT INTO alive VALUES($$committed-before-sigquit$$);
|
||||||
SELECT pg_backend_pid();
|
SELECT pg_backend_pid();
|
||||||
];
|
];
|
||||||
ok(pump_until($killme, \$killme_stdout, qr/[[:digit:]]+[\r\n]$/m),
|
ok(TestLib::pump_until(
|
||||||
|
$killme, $psql_timeout, \$killme_stdout,
|
||||||
|
qr/[[:digit:]]+[\r\n]$/m),
|
||||||
'acquired pid for SIGQUIT');
|
'acquired pid for SIGQUIT');
|
||||||
my $pid = $killme_stdout;
|
my $pid = $killme_stdout;
|
||||||
chomp($pid);
|
chomp($pid);
|
||||||
@ -84,7 +86,9 @@ $killme_stdin .= q[
|
|||||||
BEGIN;
|
BEGIN;
|
||||||
INSERT INTO alive VALUES($$in-progress-before-sigquit$$) RETURNING status;
|
INSERT INTO alive VALUES($$in-progress-before-sigquit$$) RETURNING status;
|
||||||
];
|
];
|
||||||
ok(pump_until($killme, \$killme_stdout, qr/in-progress-before-sigquit/m),
|
ok(TestLib::pump_until(
|
||||||
|
$killme, $psql_timeout, \$killme_stdout,
|
||||||
|
qr/in-progress-before-sigquit/m),
|
||||||
'inserted in-progress-before-sigquit');
|
'inserted in-progress-before-sigquit');
|
||||||
$killme_stdout = '';
|
$killme_stdout = '';
|
||||||
$killme_stderr = '';
|
$killme_stderr = '';
|
||||||
@ -97,7 +101,8 @@ $monitor_stdin .= q[
|
|||||||
SELECT $$psql-connected$$;
|
SELECT $$psql-connected$$;
|
||||||
SELECT pg_sleep(3600);
|
SELECT pg_sleep(3600);
|
||||||
];
|
];
|
||||||
ok(pump_until($monitor, \$monitor_stdout, qr/psql-connected/m),
|
ok(TestLib::pump_until(
|
||||||
|
$monitor, $psql_timeout, \$monitor_stdout, qr/psql-connected/m),
|
||||||
'monitor connected');
|
'monitor connected');
|
||||||
$monitor_stdout = '';
|
$monitor_stdout = '';
|
||||||
$monitor_stderr = '';
|
$monitor_stderr = '';
|
||||||
@ -112,8 +117,9 @@ is($ret, 0, "killed process with SIGQUIT");
|
|||||||
$killme_stdin .= q[
|
$killme_stdin .= q[
|
||||||
SELECT 1;
|
SELECT 1;
|
||||||
];
|
];
|
||||||
ok( pump_until(
|
ok( TestLib::pump_until(
|
||||||
$killme,
|
$killme,
|
||||||
|
$psql_timeout,
|
||||||
\$killme_stderr,
|
\$killme_stderr,
|
||||||
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
|
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
|
||||||
),
|
),
|
||||||
@ -125,8 +131,9 @@ $killme->finish;
|
|||||||
# Wait till server restarts - we should get the WARNING here, but
|
# Wait till server restarts - we should get the WARNING here, but
|
||||||
# sometimes the server is unable to send that, if interrupted while
|
# sometimes the server is unable to send that, if interrupted while
|
||||||
# sending.
|
# sending.
|
||||||
ok( pump_until(
|
ok( TestLib::pump_until(
|
||||||
$monitor,
|
$monitor,
|
||||||
|
$psql_timeout,
|
||||||
\$monitor_stderr,
|
\$monitor_stderr,
|
||||||
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
|
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
|
||||||
),
|
),
|
||||||
@ -153,7 +160,8 @@ $monitor->run();
|
|||||||
$killme_stdin .= q[
|
$killme_stdin .= q[
|
||||||
SELECT pg_backend_pid();
|
SELECT pg_backend_pid();
|
||||||
];
|
];
|
||||||
ok(pump_until($killme, \$killme_stdout, qr/[[:digit:]]+[\r\n]$/m),
|
ok(TestLib::pump_until(
|
||||||
|
$killme, $psql_timeout, \$killme_stdout, qr/[[:digit:]]+[\r\n]$/m),
|
||||||
"acquired pid for SIGKILL");
|
"acquired pid for SIGKILL");
|
||||||
$pid = $killme_stdout;
|
$pid = $killme_stdout;
|
||||||
chomp($pid);
|
chomp($pid);
|
||||||
@ -166,7 +174,9 @@ INSERT INTO alive VALUES($$committed-before-sigkill$$) RETURNING status;
|
|||||||
BEGIN;
|
BEGIN;
|
||||||
INSERT INTO alive VALUES($$in-progress-before-sigkill$$) RETURNING status;
|
INSERT INTO alive VALUES($$in-progress-before-sigkill$$) RETURNING status;
|
||||||
];
|
];
|
||||||
ok(pump_until($killme, \$killme_stdout, qr/in-progress-before-sigkill/m),
|
ok(TestLib::pump_until(
|
||||||
|
$killme, $psql_timeout, \$killme_stdout,
|
||||||
|
qr/in-progress-before-sigkill/m),
|
||||||
'inserted in-progress-before-sigkill');
|
'inserted in-progress-before-sigkill');
|
||||||
$killme_stdout = '';
|
$killme_stdout = '';
|
||||||
$killme_stderr = '';
|
$killme_stderr = '';
|
||||||
@ -178,7 +188,8 @@ $monitor_stdin .= q[
|
|||||||
SELECT $$psql-connected$$;
|
SELECT $$psql-connected$$;
|
||||||
SELECT pg_sleep(3600);
|
SELECT pg_sleep(3600);
|
||||||
];
|
];
|
||||||
ok(pump_until($monitor, \$monitor_stdout, qr/psql-connected/m),
|
ok(TestLib::pump_until(
|
||||||
|
$monitor, $psql_timeout, \$monitor_stdout, qr/psql-connected/m),
|
||||||
'monitor connected');
|
'monitor connected');
|
||||||
$monitor_stdout = '';
|
$monitor_stdout = '';
|
||||||
$monitor_stderr = '';
|
$monitor_stderr = '';
|
||||||
@ -194,8 +205,9 @@ is($ret, 0, "killed process with KILL");
|
|||||||
$killme_stdin .= q[
|
$killme_stdin .= q[
|
||||||
SELECT 1;
|
SELECT 1;
|
||||||
];
|
];
|
||||||
ok( pump_until(
|
ok( TestLib::pump_until(
|
||||||
$killme,
|
$killme,
|
||||||
|
$psql_timeout,
|
||||||
\$killme_stderr,
|
\$killme_stderr,
|
||||||
qr/server closed the connection unexpectedly|connection to server was lost/m
|
qr/server closed the connection unexpectedly|connection to server was lost/m
|
||||||
),
|
),
|
||||||
@ -205,8 +217,9 @@ $killme->finish;
|
|||||||
# Wait till server restarts - we should get the WARNING here, but
|
# Wait till server restarts - we should get the WARNING here, but
|
||||||
# sometimes the server is unable to send that, if interrupted while
|
# sometimes the server is unable to send that, if interrupted while
|
||||||
# sending.
|
# sending.
|
||||||
ok( pump_until(
|
ok( TestLib::pump_until(
|
||||||
$monitor,
|
$monitor,
|
||||||
|
$psql_timeout,
|
||||||
\$monitor_stderr,
|
\$monitor_stderr,
|
||||||
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
|
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
|
||||||
),
|
),
|
||||||
@ -244,33 +257,3 @@ is( $node->safe_psql(
|
|||||||
'can still write after orderly restart');
|
'can still write after orderly restart');
|
||||||
|
|
||||||
$node->stop();
|
$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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user