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

Commit 69d8f41

Browse files
kvapkelvich
authored andcommitted
Add a timeout to the deadlock tap test.
1 parent 6c71467 commit 69d8f41

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

t/000_deadlock.pl

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use PostgresNode;
55
use TestLib;
6-
use Test::More tests => 2;
6+
use Test::More tests => 1;
77

88
use DBI;
99
use DBD::Pg ':async';
@@ -14,23 +14,23 @@ sub query_row
1414
my $sth = $dbi->prepare($sql) || die;
1515
$sth->execute(@keys) || die;
1616
my $ret = $sth->fetchrow_array || undef;
17-
print "query_row('$sql') -> $ret \n";
17+
diag("query_row('$sql') -> $ret\n");
1818
return $ret;
1919
}
2020

2121
sub query_exec
2222
{
2323
my ($dbi, $sql) = @_;
2424
my $rv = $dbi->do($sql) || die;
25-
print "query_exec('$sql') = $rv\n";
25+
diag("query_exec('$sql') = $rv\n");
2626
return $rv;
2727
}
2828

2929
sub query_exec_async
3030
{
3131
my ($dbi, $sql) = @_;
3232
my $rv = $dbi->do($sql, {pg_async => PG_ASYNC}) || die;
33-
print "query_exec_async('$sql') = $rv\n";
33+
diag("query_exec_async('$sql')\n");
3434
return $rv;
3535
}
3636

@@ -44,7 +44,7 @@ sub allocate_ports
4444
{
4545
my $port = int(rand() * 16384) + 49152;
4646
next if $allocated_ports{$port};
47-
print "# Checking for port $port\n";
47+
diag("Checking for port $port\n");
4848
if (!TestLib::run_log(['pg_isready', '-h', $host, '-p', $port]))
4949
{
5050
$allocated_ports{$port} = 1;
@@ -73,8 +73,8 @@ sub allocate_ports
7373
my $mm_connstr = join(',', map { "${ \$_->connstr('postgres') }" } @nodes);
7474
my $raft_peers = join(',', map { join(':', $_->{id}, $_->host, $_->{raftport}) } @nodes);
7575

76-
print("# mm_connstr = $mm_connstr\n");
77-
print("# raft_peers = $raft_peers\n");
76+
diag("mm_connstr = $mm_connstr\n");
77+
diag("raft_peers = $raft_peers\n");
7878

7979
# Init and Configure
8080
foreach my $node (@nodes)
@@ -125,33 +125,49 @@ sub allocate_ports
125125
$nodes[0]->psql('postgres', "create table t(k int primary key, v text)");
126126
$nodes[0]->psql('postgres', "insert into t values (1, 'hello'), (2, 'world')");
127127

128-
#sub space2semicol
129-
#{
130-
# my $str = shift;
131-
# $str =~ tr/ /;/;
132-
# return $str;
133-
#}
134-
#
135128
my @conns = map { DBI->connect('DBI:Pg:' . $_->connstr()) } @nodes;
136129

137130
query_exec($conns[0], "begin");
138131
query_exec($conns[1], "begin");
139132

140133
query_exec($conns[0], "update t set v = 'asd' where k = 1");
141-
query_exec($conns[1], "update t set v = 'bsd' where k = 2");
134+
query_exec($conns[1], "update t set v = 'bsd'");
142135

143136
query_exec($conns[0], "update t set v = 'bar' where k = 2");
144-
query_exec($conns[1], "update t set v = 'foo' where k = 1");
137+
query_exec($conns[1], "update t set v = 'foo'");
145138

146139
query_exec_async($conns[0], "commit");
147140
query_exec_async($conns[1], "commit");
148141

149-
for my $i (1..2)
142+
my $timeout = 5;
143+
while ($timeout > 0)
150144
{
151-
($rc, $out, $err) = $nodes[$i]->psql('postgres', "select * from t");
152-
print(" rc[$i] = $rc\n");
153-
print("out[$i] = $out\n");
154-
print("err[$i] = $err\n");
145+
my $r0 = $conns[0]->pg_ready();
146+
my $r1 = $conns[1]->pg_ready();
147+
if ($r0 && $r1) {
148+
last;
149+
}
150+
diag("queries still running: [0]=$r0 [1]=$r1\n");
151+
sleep(1);
152+
}
153+
154+
if ($timeout > 0)
155+
{
156+
diag("queries finished\n");
157+
158+
my $succeeded = 0;
159+
$succeeded++ if $conns[0]->pg_result();
160+
$succeeded++ if $conns[1]->pg_result();
161+
162+
pass("queries finished");
163+
}
164+
else
165+
{
166+
diag("queries timed out\n");
167+
$conns[0]->pg_cancel() unless $conns[0]->pg_ready();
168+
$conns[1]->pg_cancel() unless $conns[1]->pg_ready();
169+
170+
fail("queries timed out");
155171
}
156172

157-
#sleep(2);
173+
query_row($conns[0], "select * from t where k = 1");

0 commit comments

Comments
 (0)