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

Commitde3de0a

Browse files
committed
Improve TAP test function PostgresNode::poll_query_until().
Add an optional "expected" argument to override the default assumptionthat we're waiting for the query to return "t". This allows replacinga handwritten polling loop in recovery/t/007_sync_rep.pl with use ofpoll_query_until(); AFAICS that's the only remaining ad-hoc pollingloop in our TAP tests.Change poll_query_until() to probe ten times per second not once persecond. Like some similar changes I've been making recently, theone-second interval seems to be rooted in ancient traditions ratherthan the actual likely wait duration on modern machines. I'd considerreducing it further if there were a convenient way to spawn just onepsql for the whole loop rather than one per probe attempt.Discussion:https://postgr.es/m/12486.1498938782@sss.pgh.pa.us
1 parent2dca034 commitde3de0a

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

‎src/test/perl/PostgresNode.pm

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,36 +1213,43 @@ sub psql
12131213

12141214
=pod
12151215
1216-
=item$node->poll_query_until(dbname, query)
1216+
=item$node->poll_query_until($dbname,$query [, $expected ])
12171217
1218-
Run a query once a second, until it returns 't' (i.e. SQL boolean true).
1219-
Continues polling if psql returns an error result. Times out after 180 seconds.
1218+
RunB<$query> repeatedly, until it returns theB<$expected> result
1219+
('t', or SQL boolean true, by default).
1220+
Continues polling ifB<psql> returns an error result.
1221+
Times out after 180 seconds.
1222+
Returns 1 if successful, 0 if timed out.
12201223
12211224
=cut
12221225

12231226
subpoll_query_until
12241227
{
1225-
my ($self,$dbname,$query) =@_;
1228+
my ($self,$dbname,$query,$expected) =@_;
12261229

1227-
my$max_attempts = 180;
1228-
my$attempts = 0;
1230+
$expected ='t'unlessdefined($expected);# default value
1231+
1232+
my$cmd =
1233+
['psql','-XAt','-c',$query,'-d',$self->connstr($dbname) ];
12291234
my ($stdout,$stderr);
1235+
my$max_attempts = 180 * 10;
1236+
my$attempts = 0;
12301237

12311238
while ($attempts <$max_attempts)
12321239
{
1233-
my$cmd =
1234-
['psql','-XAt','-c',$query,'-d',$self->connstr($dbname) ];
12351240
my$result = IPC::Run::run$cmd,'>', \$stdout,'2>', \$stderr;
12361241

12371242
chomp($stdout);
12381243
$stdout =~s/\r//gif$TestLib::windows_os;
1239-
if ($stdouteq"t")
1244+
1245+
if ($stdouteq$expected)
12401246
{
12411247
return 1;
12421248
}
12431249

1244-
# Wait a second before retrying.
1245-
sleep 1;
1250+
# Wait 0.1 second before retrying.
1251+
selectundef,undef,undef, 0.1;
1252+
12461253
$attempts++;
12471254
}
12481255

‎src/test/recovery/t/007_sync_rep.pl

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
my$check_sql =
1010
"SELECT application_name, sync_priority, sync_state FROM pg_stat_replication ORDER BY application_name;";
1111

12-
# Check that sync_state of each standby is expected.
12+
# Check that sync_state of each standby is expected (waiting till it is).
1313
# If $setting is given, synchronous_standby_names is set to it and
1414
# the configuration file is reloaded before the test.
1515
subtest_sync_state
@@ -23,24 +23,7 @@ sub test_sync_state
2323
$self->reload;
2424
}
2525

26-
my$timeout_max = 30;
27-
my$timeout = 0;
28-
my$result;
29-
30-
# A reload may take some time to take effect on busy machines,
31-
# hence use a loop with a timeout to give some room for the test
32-
# to pass.
33-
while ($timeout <$timeout_max)
34-
{
35-
$result =$self->safe_psql('postgres',$check_sql);
36-
37-
lastif ($resulteq$expected);
38-
39-
$timeout++;
40-
sleep 1;
41-
}
42-
43-
is($result,$expected,$msg);
26+
ok($self->poll_query_until('postgres',$check_sql,$expected),$msg);
4427
}
4528

4629
# Initialize master node

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp