Skip to content

Commit e393be8

Browse files
committed
Improve sability of 008_bugfixes.pl test.
Also make free port choosing routine work on BSD-like systems (e.g. macOS).
1 parent 78d7b8c commit e393be8

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

Cluster.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ sub mm_get_free_port
3232
{
3333

3434
# advance $port, wrapping correctly around range end
35-
$port = 26000 if ++$port == 27000;
35+
$port = 26000 if ++$port >= 27000;
3636
print "# Checking port $port\n";
3737

3838
# Check first that candidate port number is not included in
@@ -58,7 +58,7 @@ sub mm_get_free_port
5858
if ($found == 1)
5959
{
6060
foreach my $addr (qw(127.0.0.1),
61-
$PostgresNode::use_tcp ? qw(127.0.0.2 127.0.0.3 0.0.0.0) : ())
61+
$PostgresNode::use_tcp && ($^O eq "linux" || $windows_os) ? qw(127.0.0.2 127.0.0.3 0.0.0.0) : ())
6262
{
6363
if (!PostgresNode::can_bind($addr, $port))
6464
{

t/008_bugfixes.pl

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
use Carp;
2+
use POSIX;
13
use strict;
4+
use Test::More;
5+
use TestLib;
6+
use Time::HiRes qw(usleep);
27
use warnings;
3-
use Carp;
8+
49
use PostgresNode;
510
use Cluster;
6-
use TestLib;
7-
use Test::More;
11+
12+
use Test::More tests => Cluster::is_ee() ? 6 : 5;
813

914
my $cluster = new Cluster(3);
1015
$cluster->init();
@@ -42,7 +47,7 @@
4247
$hash2 = $cluster->safe_psql(2, $hash_query);
4348
note("$hash0, $hash1, $hash2");
4449
is( (($hash0 eq $hash1) and ($hash1 eq $hash2)) , 1,
45-
"Check that hash is the same after query");
50+
"Check that hash is the same after query");
4651
}
4752

4853
$cluster->safe_psql(0, q{
@@ -72,7 +77,7 @@
7277
$hash2 = $cluster->safe_psql(2, $hash_query);
7378
note("$hash0, $hash1, $hash2");
7479
is( (($hash0 eq $hash1) and ($hash1 eq $hash2)) , 1,
75-
"Check that hash is the same after query");
80+
"Check that hash is the same after query");
7681

7782
# ##############################################################################
7883
#
@@ -93,30 +98,35 @@
9398

9499
# Simulate payload
95100
$cluster->pgbench(0, ('-i', '-n', -s => '1') );
96-
my $pgb1 = $cluster->pgbench_async(0, ('-n', -T => '15', -j=>'5', -c => '5') );
97-
sleep(5);
101+
note( strftime('%Y-%m-%d %H:%M:%S', localtime) . ": starting async pgbench" );
102+
my $pgb1 = $cluster->pgbench_async(0, ('-n', -T => '25', -j => '1', -c => '5') );
98103

99104
my $pid0;
100105
my $attempts = 0;
106+
107+
note( strftime('%Y-%m-%d %H:%M:%S', localtime) . ": starting polling of backend pid" );
101108
while (1)
102109
{
103110
$pid0 = $cluster->safe_psql(0, "SELECT pid FROM pg_stat_activity
104111
WHERE backend_type LIKE 'client backend'
105112
AND query LIKE 'UPDATE%' LIMIT 1;");
106113

107114
# bf says we might be really unlucky to find no backend doing update
108-
if ($pid0 ne "")
115+
# It does not make much sense to try longer than pgbench run lasts,
116+
# since we need an active backend to kill. So let it be 25 seconds
117+
# both for pgbench_async() and this pg_stat_activity polling.
118+
if ( ($pid0 ne "") || $attempts >= 25*10 )
109119
{
110120
last;
111121
}
122+
112123
# Wait 0.1 second before retrying.
113124
usleep(100_000);
114125
$attempts++;
115-
if ($attempts >= 180*10)
116-
{
117-
croak 'failed to fetch backend pid';
118-
}
119126
}
127+
note( strftime('%Y-%m-%d %H:%M:%S', localtime) . ": finished polling of backend pid" );
128+
is( ($pid0 ne ""), 1,
129+
"found an active backend doing UPDATE" );
120130

121131
# Simulate hard crash
122132
note("Simulate hard crash of a backend by SIGKILL to $pid0");

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