summaryrefslogtreecommitdiff
path: root/t/daemonize.t
blob: a6a02b3f64933c98c50d3fad2bf647c938f5bc18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env perl

use strict;
use Test::More tests => 7;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;

use File::Temp qw(tempfile);

my (undef, $tmpfn) = tempfile();

my $server = new_memcached("-d -P $tmpfn");
my $sock = $server->sock;
sleep 0.5;

ok(-e $tmpfn, "pid file exists");
ok(-s $tmpfn, "pid file has length");

open (my $fh, $tmpfn) or die;
my $readpid = do { local $/; <$fh>; };
chomp $readpid;
close ($fh);

ok(kill(0, $readpid), "process is still running");

my $stats = mem_stats($sock);
is($stats->{pid}, $readpid, "memcached reports same pid as file");

ok($server->new_sock, "opened new socket");
ok(kill(9, $readpid), "sent KILL signal");
sleep 0.5;
ok(! $server->new_sock, "failed to open new socket");