Skip to content

Commit b469324

Browse files
committed
Implement cluster killing in tap tests.
1 parent 64911de commit b469324

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

contrib/mmts/Cluster.pm

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package Cluster;
33
use strict;
44
use warnings;
55

6+
use Proc::ProcessTable;
67
use PostgresNode;
78
use TestLib;
89
use Test::More;
@@ -135,7 +136,12 @@ sub stopnode
135136
$mode = 'fast' unless defined $mode;
136137
diag("stopping node $name ${mode}ly at $pgdata port $port");
137138
next unless defined $node->{_pid};
138-
my $ret = TestLib::system_log('pg_ctl', '-D', $pgdata, '-m', 'fast', 'stop');
139+
my $ret = 0;
140+
if ($mode eq 'kill') {
141+
killtree($node->{_pid});
142+
} else {
143+
$ret = TestLib::system_log('pg_ctl', '-D', $pgdata, '-m', 'fast', 'stop');
144+
}
139145
$node->{_pid} = undef;
140146
$node->_update_pid;
141147

@@ -147,6 +153,45 @@ sub stopnode
147153
return 1;
148154
}
149155

156+
sub killtree
157+
{
158+
my $root = shift;
159+
diag("killtree $root\n");
160+
161+
my $t = new Proc::ProcessTable;
162+
163+
my %parent = ();
164+
#my %cmd = ();
165+
foreach my $p (@{$t->table}) {
166+
$parent{$p->pid} = $p->ppid;
167+
# $cmd{$p->pid} = $p->cmndline;
168+
}
169+
170+
if (!defined $root) {
171+
return;
172+
}
173+
my @queue = ($root);
174+
my @killist = ();
175+
176+
while (scalar @queue) {
177+
my $victim = shift @queue;
178+
while (my ($pid, $ppid) = each %parent) {
179+
if ($ppid == $victim) {
180+
push @queue, $pid;
181+
}
182+
}
183+
diag("SIGSTOP to $victim");
184+
kill 'STOP', $victim;
185+
unshift @killist, $victim;
186+
}
187+
188+
diag("SIGKILL to " . join(' ', @killist));
189+
kill 'KILL', @killist;
190+
#foreach my $victim (@killist) {
191+
# print("kill $victim " . $cmd{$victim} . "\n");
192+
#}
193+
}
194+
150195
sub stop
151196
{
152197
my ($self, $mode) = @_;
@@ -155,8 +200,8 @@ sub stop
155200

156201
my $ok = 1;
157202
diag("stopping cluster ${mode}ly");
158-
foreach my $node (@$nodes)
159-
{
203+
204+
foreach my $node (@$nodes) {
160205
if (!stopnode($node, $mode)) {
161206
$ok = 0;
162207
if (!stopnode($node, 'immediate')) {

contrib/mmts/t/000_deadlock.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@ sub query_exec_async
9393

9494
query_row($conns[0], "select * from t where k = 1");
9595

96-
ok($cluster->stop(), "cluster stops");
96+
ok($cluster->stop('kill'), "cluster stops");
9797
1;

contrib/mmts/t/001_basic_recovery.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@
108108

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

111-
ok($cluster->stop(), "cluster stops");
111+
ok($cluster->stop('kill'), "cluster stops");
112112
1;

contrib/mmts/t/002_cross.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,5 @@ sub parse_state
150150

151151
is($anomalies, 0, "no cross anomalies after $selects selects");
152152

153-
ok($cluster->stop(), "cluster stops");
153+
ok($cluster->stop('kill'), "cluster stops");
154154
1;

contrib/mmts/t/003_pgbench.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ sub writer
110110
($rc, $out, $err) = $cluster->psql(0, 'postgres', "select count(*) from reader_log where v = 0;");
111111
isnt($out, 0, "there are some zeros in reader_log");
112112

113-
ok($cluster->stop(), "cluster stops");
113+
ok($cluster->stop('kill'), "cluster stops");
114114
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