summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/p5-Server-Starter/t/12-stop.t
blob: 6d40c25f59ab94c81edfb61ffcbfad8054d96726 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use strict;
use warnings;
use utf8;
use Test::More;
use Server::Starter qw(start_server restart_server stop_server); 
use File::Temp qw(tempdir);
use Test::TCP;

plan tests => 2;

my $dir = tempdir( CLEANUP => 1 );
my $pidfile = "$dir/pid";

test_tcp(
   server => sub {
        my $port = shift;

        start_server(
            pid_file  => $pidfile,
            daemonize => 1,
            port      => $port,
            exec      => [ $^X, 't/12-stop-server.pl' ],
        );
        exit 0;
    },
    client => sub {
        my $port = shift;

        while (!-s $pidfile) {
            note 'pid file is not available';
            sleep 1; # wait pid file
        }

        my $pid = do {
            open my $fh, '<', $pidfile
                or die "Cannot open $pidfile: $!";
            local $/;
            <$fh>;
        };
        note "PID=$pid";
        is(kill(0, $pid), 1, 'there is a process');

        stop_server(
            pid_file => $pidfile,
            port => $port,
        );
        ok((!-e $pidfile), 'pid file was unlinked');
    },
);