Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bc587d0

Browse files
committed
replace sleeps with awaiting in 004_recovery.pl
1 parent 5479ed5 commit bc587d0

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

Cluster.pm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,14 @@ sub add_node()
400400
push(@{$self->{nodes}}, $node);
401401
}
402402

403+
sub await_nodes()
404+
{
405+
my ($self, @nodenums) = @_;
406+
407+
foreach my $i (@nodenums)
408+
{
409+
$self->{nodes}->[$i]->poll_query_until('postgres', "select 't'");
410+
}
411+
}
412+
403413
1;

t/004_recovery.pl

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
use warnings;
33
use Cluster;
44
use TestLib;
5-
use Test::More tests => 4;
5+
use Test::More tests => 6;
66

77

88
my $cluster = new Cluster(3);
99
$cluster->init();
1010
$cluster->configure();
1111
$cluster->start();
12-
sleep(10);
12+
$cluster->await_nodes( (0,1,2) );
1313

1414
########################################################
1515
# Check data integrity before and after recovery
@@ -29,7 +29,6 @@
2929
(select * from pgbench_accounts order by aid) t;";
3030

3131
$cluster->{nodes}->[2]->stop('fast');
32-
sleep(3);
3332

3433
$cluster->pgbench(0, ('-n','-N', -T => '4') );
3534
$cluster->pgbench(1, ('-n','-N', -T => '4') );
@@ -42,7 +41,7 @@
4241
$oldhash = $hash0;
4342

4443
$cluster->{nodes}->[2]->start;
45-
sleep(10);
44+
$cluster->await_nodes( (2) );
4645

4746
$cluster->psql(0, 'postgres', $hash_query, stdout => \$hash0);
4847
$cluster->psql(1, 'postgres', $hash_query, stdout => \$hash1);
@@ -61,19 +60,16 @@
6160
$cluster->psql(0, 'postgres', "insert into t values(1, 10);");
6261
$cluster->psql(1, 'postgres', "insert into t values(2, 20);");
6362
$cluster->psql(2, 'postgres', "insert into t values(3, 30);");
64-
sleep(2);
6563

6664
my $sum0; my $sum1; my $sum2;
6765

6866
$cluster->{nodes}->[1]->stop('fast');
6967
$cluster->{nodes}->[2]->stop('fast');
7068

71-
sleep(5);
7269
$cluster->{nodes}->[1]->start;
73-
# try to start node3 right here?
74-
sleep(5);
7570
$cluster->{nodes}->[2]->start;
76-
sleep(5);
71+
72+
$cluster->await_nodes( (0,1,2) );
7773

7874
$cluster->psql(0, 'postgres', "select sum(v) from t;", stdout => \$sum0);
7975
$cluster->psql(1, 'postgres', "select sum(v) from t;", stdout => \$sum1);
@@ -90,19 +86,19 @@
9086
$cluster->pgbench(2, ('-N', -T => '1') );
9187

9288
# kill node while neighbour is under load
93-
my $pgb_handle = $cluster->pgbench_async(1, ('-N', -T => '10') );
89+
my $pgb_handle = $cluster->pgbench_async(1, ('-N', -T => '20') );
9490
sleep(5);
9591
$cluster->{nodes}->[2]->stop('fast');
9692
$cluster->pgbench_await($pgb_handle);
9793

9894
# start node while neighbour is under load
99-
$pgb_handle = $cluster->pgbench_async(0, ('-N', -T => '50') );
100-
sleep(10);
95+
$pgb_handle = $cluster->pgbench_async(0, ('-N', -T => '20') );
96+
sleep(5);
10197
$cluster->{nodes}->[2]->start;
10298
$cluster->pgbench_await($pgb_handle);
10399

104-
# give it extra 10s to recover
105-
sleep(10);
100+
# await recovery
101+
$cluster->await_nodes( (2) );
106102

107103
# check data identity
108104
$cluster->psql(0, 'postgres', $hash_query, stdout => \$hash0);
@@ -111,17 +107,13 @@
111107
note("$hash0, $hash1, $hash2");
112108
is( (($hash0 == $hash1) and ($hash1 == $hash2)) , 1, "Check that hash is the same");
113109

114-
# $cluster->psql(0, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum0);
115-
# $cluster->psql(1, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum1);
116-
# $cluster->psql(2, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum2);
117-
118-
# note("Sums: $sum0, $sum1, $sum2");
119-
# is($sum2, $sum0, "Check that sum_2 == sum_0");
120-
# is($sum2, $sum1, "Check that sum_2 == sum_1");
110+
$cluster->psql(0, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum0);
111+
$cluster->psql(1, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum1);
112+
$cluster->psql(2, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum2);
121113

122-
if ($sum2 == '') {
123-
sleep(3600);
124-
}
114+
note("Sums: $sum0, $sum1, $sum2");
115+
is($sum2, $sum0, "Check that sum_2 == sum_0");
116+
is($sum2, $sum1, "Check that sum_2 == sum_1");
125117

126118
$cluster->{nodes}->[0]->stop('fast');
127119
$cluster->{nodes}->[1]->stop('fast');

0 commit comments

Comments
 (0)