summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2020-11-20 15:40:12 -0800
committerdormando <dormando@rydia.net>2020-11-20 15:40:12 -0800
commitc472369fed5981ba8c004d426cee62d5165c47ca (patch)
treeabaa56fe8812a9d2b38d4463f7ff29ce66230c4e
parent4821f7e8737f0265f032aa1c3318aeb871015f16 (diff)
downloadmemcached-c472369fed5981ba8c004d426cee62d5165c47ca.tar.gz
improve shutdown tests1.6.9
new tests were flaky for slow systems; for some reason writing to the closet socket would exit prove instead of throw any kind of error. Instead we check that the child pid actually exits and loop a bit to avoid the race.
-rw-r--r--t/lib/MemcachedTest.pm7
-rw-r--r--t/shutdown.t20
2 files changed, 23 insertions, 4 deletions
diff --git a/t/lib/MemcachedTest.pm b/t/lib/MemcachedTest.pm
index cb5bd15..b39271d 100644
--- a/t/lib/MemcachedTest.pm
+++ b/t/lib/MemcachedTest.pm
@@ -387,6 +387,7 @@ END {
############################################################################
package Memcached::Handle;
+use POSIX ":sys_wait_h";
sub new {
my ($class, %params) = @_;
return bless \%params, $class;
@@ -407,6 +408,12 @@ sub graceful_stop {
kill 'SIGUSR1', $self->{pid};
}
+# -1 if the pid is actually dead.
+sub is_running {
+ my $self = shift;
+ return waitpid($self->{pid}, WNOHANG) >= 0 ? 1 : 0;
+}
+
sub host { $_[0]{host} }
sub port { $_[0]{port} }
sub udpport { $_[0]{udpport} }
diff --git a/t/shutdown.t b/t/shutdown.t
index 6dfbd77..1d2d0c4 100644
--- a/t/shutdown.t
+++ b/t/shutdown.t
@@ -31,8 +31,7 @@ use MemcachedTest;
print $sock "version\r\n";
like(scalar <$sock>, qr/VERSION/, "server is initially alive");
print $sock "shutdown\r\n";
- print $sock "version\r\n";
- is(scalar <$sock>, undef, "server has been normally shut down");
+ still_going($server);
}
# Graceful shutdown
@@ -42,8 +41,21 @@ use MemcachedTest;
print $sock "version\r\n";
like(scalar <$sock>, qr/VERSION/, "server is initially alive");
print $sock "shutdown graceful\r\n";
- print $sock "version\r\n";
- is(scalar <$sock>, undef, "server has been gracefully shut down");
+ still_going($server);
+}
+
+sub still_going {
+ my $server = shift;
+ for (1..10) {
+ if ($server->is_running) {
+ sleep 1;
+ } else {
+ ok(!$server->is_running, "server stopped");
+ return;
+ }
+ }
+
+ ok(0, "server failed to stop");
}
done_testing();