File: 30loop-detachchild.t

package info (click to toggle)
libio-async-perl 0.29-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 684 kB
  • ctags: 239
  • sloc: perl: 6,439; makefile: 2
file content (65 lines) | stat: -rw-r--r-- 1,422 bytes parent folder | download
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
#!/usr/bin/perl -w

use strict;

use IO::Async::Test;

use Test::More tests => 6;
use Test::Exception;

use POSIX qw( SIGINT WEXITSTATUS WIFSIGNALED WTERMSIG );

use IO::Async::Loop::Poll;

my $loop = IO::Async::Loop::Poll->new();

testing_loop( $loop );

my $exitcode;

sub wait_for_exit
{
   undef $exitcode;
   return wait_for { defined $exitcode };
}

$loop->detach_child(
   code    => sub { return 5; },
   on_exit => sub { ( undef, $exitcode ) = @_ },
);

wait_for_exit;

is( WEXITSTATUS($exitcode), 5, 'WEXITSTATUS($exitcode) after child exit' );

$loop->detach_child(
   code    => sub { die "error"; },
   on_exit => sub { ( undef, $exitcode ) = @_ },
);

wait_for_exit;

is( WEXITSTATUS($exitcode), 255, 'WEXITSTATUS($exitcode) after child die' );

$SIG{INT} = sub { exit( 22 ) };

$loop->detach_child(
   code    => sub { kill SIGINT, $$ },
   on_exit => sub { ( undef, $exitcode ) = @_ },
);

wait_for_exit;

is( WIFSIGNALED($exitcode), 1, 'WIFSIGNALED($exitcode) after child SIGINT' );
is( WTERMSIG($exitcode), SIGINT, 'WTERMSIG($exitcode) after child SIGINT' );

$loop->detach_child(
   code    => sub { kill SIGINT, $$ },
   on_exit => sub { ( undef, $exitcode ) = @_ },
   keep_signals => 1,
);

wait_for_exit;

is( WIFSIGNALED($exitcode), 0, 'WIFSIGNALED($exitcode) after child SIGINT with keep_signals' );
is( WEXITSTATUS($exitcode), 22, 'WEXITSTATUS($exitcode) after child SIGINT with keep_signals' );