Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit290acac

Browse files
author
Amit Kapila
committed
Move pump_until to TestLib.pm.
The subroutine pump_until provides the functionality to poll until thegiven string is matched, or a timeout occurs.  This can be used from otherplaces as well, so moving it to TestLib.pm.  The immediate need is for anupcoming regression test patch for dropdb utility.Author: Vignesh CReviewed-by: Amit KapilaDiscussion:https://postgr.es/m/CAP_rwwmLJJbn70vLOZFpxGw3XD7nLB_7+NKz46H5EOO2k5H7OQ@mail.gmail.com
1 parent60b35b7 commit290acac

File tree

2 files changed

+60
-40
lines changed

2 files changed

+60
-40
lines changed

‎src/test/perl/TestLib.pm

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,43 @@ sub command_checks_all
860860

861861
=pod
862862
863+
=itempump_until(proc, timeout, stream, untl)
864+
865+
# Pump until string is matched, or timeout occurs
866+
867+
=cut
868+
869+
subpump_until
870+
{
871+
my ($proc,$timeout,$stream,$untl) =@_;
872+
$proc->pump_nb();
873+
while (1)
874+
{
875+
lastif$$stream =~/$untl/;
876+
if ($timeout->is_expired)
877+
{
878+
diag("aborting wait: program timed out");
879+
diag("stream contents: >>",$$stream,"<<");
880+
diag("pattern searched for:",$untl);
881+
882+
return 0;
883+
}
884+
if (not$proc->pumpable())
885+
{
886+
diag("aborting wait: program died");
887+
diag("stream contents: >>",$$stream,"<<");
888+
diag("pattern searched for:",$untl);
889+
890+
return 0;
891+
}
892+
$proc->pump();
893+
}
894+
return 1;
895+
896+
}
897+
898+
=pod
899+
863900
=back
864901
865902
=cut

‎src/test/recovery/t/013_crash_restart.pl

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@
7272
INSERT INTO alive VALUES($$committed-before-sigquit$$);
7373
SELECT pg_backend_pid();
7474
];
75-
ok(pump_until($killme, \$killme_stdout,qr/[[:digit:]]+[\r\n]$/m),
75+
ok(TestLib::pump_until(
76+
$killme,$psql_timeout, \$killme_stdout,
77+
qr/[[:digit:]]+[\r\n]$/m),
7678
'acquired pid for SIGQUIT');
7779
my$pid =$killme_stdout;
7880
chomp($pid);
@@ -84,7 +86,9 @@
8486
BEGIN;
8587
INSERT INTO alive VALUES($$in-progress-before-sigquit$$) RETURNING status;
8688
];
87-
ok(pump_until($killme, \$killme_stdout,qr/in-progress-before-sigquit/m),
89+
ok(TestLib::pump_until(
90+
$killme,$psql_timeout, \$killme_stdout,
91+
qr/in-progress-before-sigquit/m),
8892
'inserted in-progress-before-sigquit');
8993
$killme_stdout ='';
9094
$killme_stderr ='';
@@ -97,7 +101,8 @@
97101
SELECT $$psql-connected$$;
98102
SELECT pg_sleep(3600);
99103
];
100-
ok(pump_until($monitor, \$monitor_stdout,qr/psql-connected/m),
104+
ok(TestLib::pump_until(
105+
$monitor,$psql_timeout, \$monitor_stdout,qr/psql-connected/m),
101106
'monitor connected');
102107
$monitor_stdout ='';
103108
$monitor_stderr ='';
@@ -112,8 +117,9 @@
112117
$killme_stdin .=q[
113118
SELECT 1;
114119
];
115-
ok( pump_until(
120+
ok(TestLib::pump_until(
116121
$killme,
122+
$psql_timeout,
117123
\$killme_stderr,
118124
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
119125
),
@@ -125,8 +131,9 @@
125131
# Wait till server restarts - we should get the WARNING here, but
126132
# sometimes the server is unable to send that, if interrupted while
127133
# sending.
128-
ok( pump_until(
134+
ok(TestLib::pump_until(
129135
$monitor,
136+
$psql_timeout,
130137
\$monitor_stderr,
131138
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
132139
),
@@ -153,7 +160,8 @@
153160
$killme_stdin .=q[
154161
SELECT pg_backend_pid();
155162
];
156-
ok(pump_until($killme, \$killme_stdout,qr/[[:digit:]]+[\r\n]$/m),
163+
ok(TestLib::pump_until(
164+
$killme,$psql_timeout, \$killme_stdout,qr/[[:digit:]]+[\r\n]$/m),
157165
"acquired pid for SIGKILL");
158166
$pid =$killme_stdout;
159167
chomp($pid);
@@ -166,7 +174,9 @@
166174
BEGIN;
167175
INSERT INTO alive VALUES($$in-progress-before-sigkill$$) RETURNING status;
168176
];
169-
ok(pump_until($killme, \$killme_stdout,qr/in-progress-before-sigkill/m),
177+
ok(TestLib::pump_until(
178+
$killme,$psql_timeout, \$killme_stdout,
179+
qr/in-progress-before-sigkill/m),
170180
'inserted in-progress-before-sigkill');
171181
$killme_stdout ='';
172182
$killme_stderr ='';
@@ -178,7 +188,8 @@
178188
SELECT $$psql-connected$$;
179189
SELECT pg_sleep(3600);
180190
];
181-
ok(pump_until($monitor, \$monitor_stdout,qr/psql-connected/m),
191+
ok(TestLib::pump_until(
192+
$monitor,$psql_timeout, \$monitor_stdout,qr/psql-connected/m),
182193
'monitor connected');
183194
$monitor_stdout ='';
184195
$monitor_stderr ='';
@@ -194,8 +205,9 @@
194205
$killme_stdin .=q[
195206
SELECT 1;
196207
];
197-
ok( pump_until(
208+
ok(TestLib::pump_until(
198209
$killme,
210+
$psql_timeout,
199211
\$killme_stderr,
200212
qr/server closed the connection unexpectedly|connection to server was lost/m
201213
),
@@ -205,8 +217,9 @@
205217
# Wait till server restarts - we should get the WARNING here, but
206218
# sometimes the server is unable to send that, if interrupted while
207219
# sending.
208-
ok( pump_until(
220+
ok(TestLib::pump_until(
209221
$monitor,
222+
$psql_timeout,
210223
\$monitor_stderr,
211224
qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly|connection to server was lost/m
212225
),
@@ -244,33 +257,3 @@
244257
'can still write after orderly restart');
245258

246259
$node->stop();
247-
248-
# Pump until string is matched, or timeout occurs
249-
subpump_until
250-
{
251-
my ($proc,$stream,$untl) =@_;
252-
$proc->pump_nb();
253-
while (1)
254-
{
255-
lastif$$stream =~/$untl/;
256-
if ($psql_timeout->is_expired)
257-
{
258-
diag("aborting wait: program timed out");
259-
diag("stream contents: >>",$$stream,"<<");
260-
diag("pattern searched for:",$untl);
261-
262-
return 0;
263-
}
264-
if (not$proc->pumpable())
265-
{
266-
diag("aborting wait: program died");
267-
diag("stream contents: >>",$$stream,"<<");
268-
diag("pattern searched for:",$untl);
269-
270-
return 0;
271-
}
272-
$proc->pump();
273-
}
274-
return 1;
275-
276-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp