-
Notifications
You must be signed in to change notification settings - Fork 135
/
kill.t
73 lines (63 loc) · 2.02 KB
/
kill.t
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
69
70
71
72
73
use Test;
use lib $?FILE.IO.parent(2).add("packages/Test-Helpers");
use Test::Util;
# ignore SIGPIPE from writing to a child process
try {
signal(::('SIGPIPE')).act: {};
}
my @signals = SIGINT;
plan 2 + @signals * 6;
for @signals -> $signal {
my $program = (make-temp-file content => q:to/END/).absolute;
signal(\qq[$signal]).act: { .say; exit };
say 'Started';
my $ = get();
exit 1; # should actually not get here
END
with Proc::Async.new($*EXECUTABLE, $program, :w) -> $proc {
isa-ok $proc, Proc::Async;
my $so = $proc.stdout;
cmp-ok $so, '~~', Supply;
react {
whenever $proc.stdout.lines {
when 'Started' {
$proc.kill($signal);
}
default {
is $_, $signal, 'Output correct for Supply.merge on signals';
}
}
whenever $proc.start {
can-ok $_, 'exitcode';
is .?exitcode, 0, 'did it exit with the right value';
is .?signal, 0, "signal $signal got handled";
}
}
}
}
# https://github.com/Raku/old-issue-tracker/issues/6304
doesn't-hang 「
await ^4 .map: -> $n {
start {
with Proc::Async.new: $*EXECUTABLE, "-e", "sleep" -> $p {
start {
await $p.ready;
$n == 3 ?? $p.kill !! $p.kill: (SIGTERM, 'TERM', SIGTERM.value)[$n]
}
await $p.start
}
}
}
print 'All done!'
」, :out('All done!'), :err(''), :10wait,
'.kill kills when multi-procs kill in multi-promises';
# https://github.com/Raku/old-issue-tracker/issues/4418
subtest 'can rapid-kill our Proc::Async without hanging' => {
plan 1;
my $proc = Proc::Async.new: $*EXECUTABLE, "-e", "sleep";
my $prom = $proc.start;
$proc.kill;
$ = await $prom;
pass 'did not hang';
}
# vim: expandtab shiftwidth=4