Skip to content

Commit 742c2b9

Browse files
committed
Use the Cluster perl module in 000_deadlock test.
1 parent 2a97cc9 commit 742c2b9

File tree

1 file changed

+8
-87
lines changed

1 file changed

+8
-87
lines changed

contrib/mmts/t/000_deadlock.pl

Lines changed: 8 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use strict;
22
use warnings;
33

4-
use PostgresNode;
4+
use Cluster;
55
use TestLib;
66
use Test::More tests => 1;
77

@@ -34,98 +34,19 @@ sub query_exec_async
3434
return $rv;
3535
}
3636

37-
my %allocated_ports = ();
38-
sub allocate_ports
39-
{
40-
my @allocated_now = ();
41-
my ($host, $ports_to_alloc) = @_;
42-
43-
while ($ports_to_alloc > 0)
44-
{
45-
my $port = int(rand() * 16384) + 49152;
46-
next if $allocated_ports{$port};
47-
diag("Checking for port $port\n");
48-
if (!TestLib::run_log(['pg_isready', '-h', $host, '-p', $port]))
49-
{
50-
$allocated_ports{$port} = 1;
51-
push(@allocated_now, $port);
52-
$ports_to_alloc--;
53-
}
54-
}
55-
56-
return @allocated_now;
57-
}
58-
59-
my $nnodes = 2;
60-
my @nodes = ();
61-
62-
# Create nodes and allocate ports
63-
foreach my $i (1..$nnodes)
64-
{
65-
my $host = "127.0.0.1";
66-
my ($pgport, $raftport) = allocate_ports($host, 2);
67-
my $node = new PostgresNode("node$i", $host, $pgport);
68-
$node->{id} = $i;
69-
$node->{raftport} = $raftport;
70-
push(@nodes, $node);
71-
}
37+
my $cluster = new Cluster(2);
7238

73-
my $mm_connstr = join(',', map { "${ \$_->connstr('postgres') }" } @nodes);
74-
my $raft_peers = join(',', map { join(':', $_->{id}, $_->host, $_->{raftport}) } @nodes);
75-
76-
diag("mm_connstr = $mm_connstr\n");
77-
diag("raft_peers = $raft_peers\n");
78-
79-
# Init and Configure
80-
foreach my $node (@nodes)
81-
{
82-
my $id = $node->{id};
83-
my $host = $node->host;
84-
my $pgport = $node->port;
85-
my $raftport = $node->{raftport};
86-
87-
$node->init(hba_permit_replication => 0);
88-
$node->append_conf("postgresql.conf", qq(
89-
listen_addresses = '$host'
90-
unix_socket_directories = ''
91-
port = $pgport
92-
max_prepared_transactions = 10
93-
max_worker_processes = 10
94-
wal_level = logical
95-
fsync = off
96-
max_wal_senders = 10
97-
wal_sender_timeout = 0
98-
max_replication_slots = 10
99-
shared_preload_libraries = 'raftable,multimaster'
100-
multimaster.workers = 4
101-
multimaster.queue_size = 10485760 # 10mb
102-
multimaster.node_id = $id
103-
multimaster.conn_strings = '$mm_connstr'
104-
multimaster.use_raftable = true
105-
raftable.id = $id
106-
raftable.peers = '$raft_peers'
107-
));
108-
109-
$node->append_conf("pg_hba.conf", qq(
110-
local replication all trust
111-
host replication all 127.0.0.1/32 trust
112-
host replication all ::1/128 trust
113-
));
114-
}
115-
116-
# Start
117-
foreach my $node (@nodes)
118-
{
119-
$node->start();
120-
}
39+
$cluster->init();
40+
$cluster->configure();
41+
$cluster->start();
12142

12243
my ($rc, $out, $err);
12344
sleep(10);
12445

125-
$nodes[0]->psql('postgres', "create table t(k int primary key, v text)");
126-
$nodes[0]->psql('postgres', "insert into t values (1, 'hello'), (2, 'world')");
46+
$cluster->psql(0, 'postgres', "create table t(k int primary key, v text)");
47+
$cluster->psql(0, 'postgres', "insert into t values (1, 'hello'), (2, 'world')");
12748

128-
my @conns = map { DBI->connect('DBI:Pg:' . $_->connstr()) } @nodes;
49+
my @conns = map { DBI->connect('DBI:Pg:' . $_->connstr()) } @{$cluster->{nodes}};
12950

13051
query_exec($conns[0], "begin");
13152
query_exec($conns[1], "begin");

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