Skip to content

Commit 9499f28

Browse files
committed
add pgbench-based recovery test
1 parent 4444c22 commit 9499f28

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

Cluster.pm

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use Cwd;
1010

1111
use Socket;
1212

13+
use IPC::Run;
14+
1315
sub check_port
1416
{
1517
my ($host, $port) = @_;
@@ -27,7 +29,6 @@ sub check_port
2729
}
2830

2931
close(SOCK);
30-
diag("checking for port $port = $available\n");
3132
return $available;
3233
}
3334

@@ -148,6 +149,7 @@ sub start
148149
foreach my $node (@$nodes)
149150
{
150151
$node->start();
152+
diag "Starting node with connstr 'dbname=postgres port=@{[ $node->port() ]} host=@{[ $node->host() ]}'";
151153
}
152154
}
153155

@@ -272,4 +274,37 @@ sub poll
272274
return 0;
273275
}
274276

277+
sub pgbench()
278+
{
279+
my ($self, $node, @args) = @_;
280+
my $pgbench_handle = $self->pgbench_async($node, @args);
281+
$self->pgbench_await($pgbench_handle);
282+
}
283+
284+
sub pgbench_async()
285+
{
286+
my ($self, $node, @args) = @_;
287+
288+
my ($in, $out, $err, $rc);
289+
$in = '';
290+
$out = '';
291+
292+
my @pgbench_command = (
293+
'pgbench',
294+
@args,
295+
-h => $self->{nodes}->[$node]->host(),
296+
-p => $self->{nodes}->[$node]->port(),
297+
'postgres',
298+
);
299+
# diag("running pgbench init");
300+
my $handle = IPC::Run::start(\@pgbench_command, $in, $out);
301+
return $handle;
302+
}
303+
304+
sub pgbench_await()
305+
{
306+
my ($self, $pgbench_handle) = @_;
307+
IPC::Run::finish($pgbench_handle) || BAIL_OUT("pgbench exited with $?");
308+
}
309+
275310
1;

t/004_recovery.pl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use strict;
2+
use warnings;
3+
use Cluster;
4+
use TestLib;
5+
use Test::More tests => 2;
6+
7+
my $cluster = new Cluster(3);
8+
$cluster->init();
9+
$cluster->configure();
10+
$cluster->start();
11+
sleep(10);
12+
13+
$cluster->psql(0, 'postgres', "create extension multimaster");
14+
$cluster->pgbench(0, ('-i', -s => '10') );
15+
16+
# kill node while neighbour is under load
17+
my $pgb_handle = $cluster->pgbench_async(0, ('-N', -T => '10') );
18+
sleep(5);
19+
$cluster->{nodes}->[2]->stop('fast');
20+
$cluster->pgbench_await($pgb_handle);
21+
22+
# start node while neighbour is under load
23+
$pgb_handle = $cluster->pgbench_async(0, ('-N', -T => '10') );
24+
sleep(5);
25+
$cluster->{nodes}->[2]->start;
26+
$cluster->pgbench_await($pgb_handle);
27+
28+
# give it 10s to recover
29+
sleep(10);
30+
31+
# check data identity
32+
my $sum0;
33+
my $sum1;
34+
my $sum2;
35+
$cluster->psql(0, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum0);
36+
$cluster->psql(1, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum1);
37+
$cluster->psql(2, 'postgres', "select sum(abalance) from pgbench_accounts;", stdout => \$sum2);
38+
39+
diag("Sums: $sum0, $sum1, $sum2");
40+
is($sum2, $sum0, "Check that sum_2 == sum_0");
41+
is($sum2, $sum1, "Check that sum_2 == sum_1");

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