File: 08_exit.t

package info (click to toggle)
libtest-tcp-perl 2.00-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 204 kB
  • sloc: perl: 233; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,269 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More tests => 5;
use Test::TCP;
use File::Temp ();
use Fcntl qw/:seek/;
use t::Server;
use POSIX;

my $tmp = File::Temp->new();

my $pid = fork();
die "cannot fork: $!" unless defined $pid;
if ($pid) { # parent
    # waiting 'client'
    SKIP: {
        waitpid($pid, 0);
        skip 'not implemented on Win32', 4 if $^O eq 'MSWin32';
        ok WIFEXITED($?);
        ok !WIFSIGNALED($?);
        ok !WIFSTOPPED($?);
        is WEXITSTATUS($?), 1;
    }

    # killing 'server'
    {
        seek $tmp, 0, SEEK_SET;
        my $child_pid = do { local $/; <$tmp> };
        is kill(($^O eq 'MSWin32' ? 'KILL' : 'TERM'), $child_pid), 0;
        my $kid;
        do {
            $kid = waitpid($child_pid, 0);
        } while $kid > 0;
    }
} else { # child
    test_tcp(
        client => sub {
            my $port = shift;
            note "CLIENT: $$";
            exit 1;
        },
        server => sub {
            my $port = shift;
            note "SEVER: $$";
            print {$tmp} $$;
            $tmp->close;
            t::Server->new($port)->run(sub {
                note "new request";
                my ($remote, $line, $sock) = @_;
                print {$remote} $line;
            });
        },
    );
}