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

Commit cd95870

Browse files
committed
evict all sleep-based awaiting in tap tests
1 parent bc587d0 commit cd95870

7 files changed

+27
-64
lines changed

Cluster.pm

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,8 @@ sub stop
225225
note("stopping cluster ${mode}ly");
226226

227227
foreach my $node (@$nodes) {
228-
if (!stopnode($node, $mode)) {
229-
$ok = 0;
230-
# if (!stopnode($node, 'kill')) {
231-
# my $name = $node->name;
232-
# BAIL_OUT("failed to kill $name");
233-
# }
234-
}
228+
$node->stop($mode);
235229
}
236-
sleep(2);
237230

238231
$self->dumplogs();
239232

@@ -313,6 +306,7 @@ sub pgbench_async()
313306
sub pgbench_await()
314307
{
315308
my ($self, $pgbench_handle) = @_;
309+
note("finished pgbench");
316310
IPC::Run::finish($pgbench_handle) || BAIL_OUT("pgbench exited with $?");
317311
}
318312

@@ -328,6 +322,7 @@ sub is_data_identic()
328322
{
329323
my $current_hash = '';
330324
$self->{nodes}->[$i]->psql('postgres', $sql, stdout => \$current_hash);
325+
note("hash$i: $current_hash");
331326
if ($current_hash eq '')
332327
{
333328
note("got empty hash from node $i");

t/000_truncate.pl

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,29 @@
1313
$cluster->init();
1414
$cluster->configure();
1515
$cluster->start();
16-
note("sleeping 10");
17-
sleep(10);
16+
$cluster->await_nodes( (0,1) );
1817

19-
my ($in, $out, $err, $rc);
18+
my ($out, $err, $rc);
2019
my $seconds = 30;
21-
$in = '';
20+
my $total_err = '';
2221
$out = '';
2322

24-
my @init_argv = (
25-
'pgbench',
26-
'-i',
27-
-h => $cluster->{nodes}->[0]->host(),
28-
-p => $cluster->{nodes}->[0]->port(),
29-
'postgres',
30-
);
31-
note("running pgbench init");
32-
my $init_run = start(\@init_argv, $in, $out);
33-
finish($init_run) || BAIL_OUT("pgbench exited with $?");
34-
35-
my @bench_argv = (
36-
'pgbench',
37-
"-T $seconds",
38-
'-N',
39-
'-c 8',
40-
-h => $cluster->{nodes}->[0]->host(),
41-
-p => $cluster->{nodes}->[0]->port(),
42-
'postgres',
43-
);
44-
note("running pgbench: " . join(' ', @bench_argv));
45-
my $bench_run = start(\@bench_argv, $in, $out);
46-
sleep(2);
23+
$cluster->pgbench(0, ('-i', -s => '1') );
24+
my $pgb_handle = $cluster->pgbench_async(0, ('-N', '-n', -T => $seconds, -c => 8) );
4725

4826
my $started = time();
4927
while (time() - $started < $seconds)
5028
{
5129
($rc, $out, $err) = $cluster->psql(1, 'postgres', "truncate pgbench_history;");
52-
($rc, $out, $err) = $cluster->psql(1, 'postgres', "vacuum full");
53-
($rc, $out, $err) = $cluster->psql(0, 'postgres', "truncate pgbench_history;");
54-
($rc, $out, $err) = $cluster->psql(0, 'postgres', "vacuum full");
55-
sleep(0.5);
30+
note("truncated");
31+
$total_err .= $err;
32+
sleep(1);
33+
# ($rc, $out, $err) = $cluster->psql(0, 'postgres', "truncate pgbench_history;");
34+
# $total_err .= $err;
35+
# sleep(0.5);
5636
}
37+
$cluster->pgbench_await($pgb_handle);
5738

58-
finish($bench_run) || $cluster->bail_out_with_logs("pgbench exited with $?");
59-
sleep(1);
60-
ok($cluster->stop('fast'), "cluster stops");
39+
is($total_err, '', "truncate successful");
40+
$cluster->stop();
6141
1;

t/001_basic_recovery.pl

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

77
my $cluster = new Cluster(3);
88
$cluster->init();
99
$cluster->configure();
1010
$cluster->start();
11-
12-
###############################################################################
13-
# Wait until nodes are up
14-
###############################################################################
11+
$cluster->await_nodes( (0,1,2) );
1512

1613
my $ret;
1714
my $psql_out;
18-
# XXX: create extension on start and poll_untill status is Online
19-
sleep(10);
2015

2116
###############################################################################
2217
# Replication check
@@ -47,12 +42,9 @@
4742
$cluster->bail_out_with_logs("failed to stop $name in fast mode");
4843
}
4944

50-
sleep(5); # Wait until failure of node will be detected
51-
5245
note("inserting 2 on node 0");
5346
$ret = $cluster->psql(0, 'postgres', "insert into t values(2, 20);"); # this transaciton may fail
5447
note("tx1 status = $ret");
55-
5648

5749
note("inserting 3 on node 1");
5850
$ret = $cluster->psql(1, 'postgres', "insert into t values(3, 30);"); # this transaciton may fail
@@ -78,19 +70,13 @@
7870
note("starting node 2");
7971
$cluster->{nodes}->[2]->start;
8072

81-
sleep(5); # Wait until node is started
73+
$cluster->await_nodes( (2) );
8274

8375
note("inserting 6 on node 0 (can fail)");
8476
$cluster->psql(0, 'postgres', "insert into t values(6, 60);");
8577
note("inserting 7 on node 1 (can fail)");
8678
$cluster->psql(1, 'postgres', "insert into t values(7, 70);");
8779

88-
note("polling node 2");
89-
for (my $poller = 0; $poller < 3; $poller++) {
90-
my $pollee = 2;
91-
ok($cluster->poll($poller, 'postgres', $pollee, 10, 1), "node $pollee is online according to node $poller");
92-
}
93-
9480
note("getting cluster state");
9581
$cluster->psql(0, 'postgres', "select * from mtm.get_cluster_state();", stdout => \$psql_out);
9682
note("Node 1 status: $psql_out");
@@ -115,5 +101,5 @@
115101

116102
is($psql_out, '90', "Check replication after failed node recovery.");
117103

118-
ok($cluster->stop('fast'), "cluster stops");
104+
$cluster->stop();
119105
1;

t/002_cross.pl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
my ($rc, $in, $out, $err);
2020

21-
note("sleeping 10");
22-
sleep(10);
21+
$cluster->await_nodes( (0,1) );
2322

2423
note("preparing the tables");
2524
if ($cluster->psql(0, 'postgres', "create table t (k int primary key, v int)"))

t/003_pgbench.pl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
my ($rc, $in, $out, $err);
1818

19-
note("sleeping 10");
20-
sleep(10);
19+
$cluster->await_nodes( (0,1) );
2120

2221
note("preparing the tables");
2322
if ($cluster->psql(0, 'postgres', "create table t (k int primary key, v int)"))

t/004_recovery.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,5 @@
118118
$cluster->{nodes}->[0]->stop('fast');
119119
$cluster->{nodes}->[1]->stop('fast');
120120
$cluster->{nodes}->[2]->stop('fast');
121+
122+
1;

t/005_add_stop_node.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,5 @@
111111
is($cluster->is_data_identic( (0,1,3,4) ), 1, "hard stop / resume");
112112

113113
ok($cluster->stop('fast'), "cluster stops");
114+
115+
1;

0 commit comments

Comments
 (0)