blob: ab401dc30063d0d1f1ca032db38ffe4c750edabf (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
use strict;
use warnings;
use utf8;
use Test::More;
use Server::Starter qw(start_server stop_server);
use Server::Starter::Guard;
use File::Temp qw(tempdir);
plan tests => 1;
my $dir = tempdir( CLEANUP => 1 );
my $pidfile = "$dir/pid";
my $sockfile = "$dir/server.sock";
fork_ok(
child => sub {
start_server(
pid_file => $pidfile,
daemonize => 1,
path => $sockfile,
exec => [ $^X, qw(t/03-starter-unix-echod.pl) ],
);
},
parent => sub {
my $guard = Server::Starter::Guard->new(sub {
stop_server( pid_file => $pidfile );
});
wait_for(sub { -e $pidfile })
or BAIL_OUT("Pidfile '$pidfile' was not created in a timely fashion");
wait_for(sub { -e $sockfile })
or BAIL_OUT("Socket '$sockfile' was not created in a timely fashion");
ok(-e $sockfile, 'there is a socket');
},
) or die "fork failed: $!";
sub fork_ok {
my (%args) = @_;
my $pid = fork;
return unless defined $pid;
if ($pid == 0) {
$args{child}->();
}
else {
$args{parent}->($pid);
}
return 1;
}
sub wait_for {
my ($code, %opts) = @_;
my $times = $opts{times} || 10;
my $every = $opts{every} || 1;
while ( $times > 0 ) {
return 1 if $code->();
$times--;
sleep $every;
}
return 0;
}
|