diff options
-rw-r--r-- | t/lib/MemcachedTest.pm | 7 | ||||
-rw-r--r-- | t/shutdown.t | 20 |
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(); |