3
3
4
4
use PostgresNode;
5
5
use TestLib;
6
- use Test::Moretests => 2 ;
6
+ use Test::Moretests => 1 ;
7
7
8
8
use DBI;
9
9
use DBD::Pg' :async' ;
@@ -14,23 +14,23 @@ sub query_row
14
14
my $sth =$dbi -> prepare($sql ) ||die ;
15
15
$sth -> execute(@keys ) ||die ;
16
16
my $ret =$sth -> fetchrow_array ||undef ;
17
- print " query_row('$sql ') ->$ret \n " ;
17
+ diag( " query_row('$sql ') ->$ret \n " ) ;
18
18
return $ret ;
19
19
}
20
20
21
21
sub query_exec
22
22
{
23
23
my ($dbi ,$sql ) =@_ ;
24
24
my $rv =$dbi -> do($sql ) ||die ;
25
- print " query_exec('$sql ') =$rv \n " ;
25
+ diag( " query_exec('$sql ') =$rv \n " ) ;
26
26
return $rv ;
27
27
}
28
28
29
29
sub query_exec_async
30
30
{
31
31
my ($dbi ,$sql ) =@_ ;
32
32
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 " ) ;
34
34
return $rv ;
35
35
}
36
36
@@ -44,7 +44,7 @@ sub allocate_ports
44
44
{
45
45
my $port =int (rand () * 16384) + 49152;
46
46
next if $allocated_ports {$port };
47
- print " # Checking for port$port \n " ;
47
+ diag( " Checking for port$port \n " ) ;
48
48
if (!TestLib::run_log([' pg_isready' ,' -h' ,$host ,' -p' ,$port ]))
49
49
{
50
50
$allocated_ports {$port } = 1;
@@ -73,8 +73,8 @@ sub allocate_ports
73
73
my $mm_connstr =join (' ,' ,map {" ${\$ _->connstr('postgres') }" }@nodes );
74
74
my $raft_peers =join (' ,' ,map {join (' :' ,$_ -> {id },$_ -> host,$_ -> {raftport }) }@nodes );
75
75
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 " );
78
78
79
79
# Init and Configure
80
80
foreach my $node (@nodes )
@@ -125,33 +125,49 @@ sub allocate_ports
125
125
$nodes [0]-> psql(' postgres' ," create table t(k int primary key, v text)" );
126
126
$nodes [0]-> psql(' postgres' ," insert into t values (1, 'hello'), (2, 'world')" );
127
127
128
- # sub space2semicol
129
- # {
130
- # my $str = shift;
131
- # $str =~ tr/ /;/;
132
- # return $str;
133
- # }
134
- #
135
128
my @conns =map { DBI-> connect (' DBI:Pg:' .$_ -> connstr()) }@nodes ;
136
129
137
130
query_exec($conns [0]," begin" );
138
131
query_exec($conns [1]," begin" );
139
132
140
133
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'" );
142
135
143
136
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'" );
145
138
146
139
query_exec_async($conns [0]," commit" );
147
140
query_exec_async($conns [1]," commit" );
148
141
149
- for my $i (1..2)
142
+ my $timeout = 5;
143
+ while ($timeout > 0)
150
144
{
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" );
155
171
}
156
172
157
- # sleep(2 );
173
+ query_row( $conns [0], " select * from t where k = 1 " );