1 | $|=1; |
1 | $|=1; |
2 | BEGIN { print "1..7\n" } |
2 | BEGIN { |
|
|
3 | print "1..7\n" |
|
|
4 | } |
3 | |
5 | |
4 | use AnyEvent; |
6 | use AnyEvent; |
5 | use AnyEvent::Impl::Perl; |
7 | use AnyEvent::Impl::Perl; |
|
|
8 | |
|
|
9 | print STDERR <<EOF; |
|
|
10 | |
|
|
11 | If the following test hangs for a long time you either found a bug in |
|
|
12 | AnyEvent or, more likely, you have a defective perl (most windows perl |
|
|
13 | distros are broken, cygwin perl works). If you do not rely on child |
|
|
14 | handlers you can force the installation of this module and the rest will |
|
|
15 | likely work. Otherwise upgrading to a working perl is recommended. |
|
|
16 | EOF |
6 | |
17 | |
7 | print "ok 1\n"; |
18 | print "ok 1\n"; |
8 | |
19 | |
9 | my $pid = fork; |
20 | my $pid = fork; |
10 | |
21 | |
11 | defined $pid or die "unable to fork"; |
22 | defined $pid or die "unable to fork"; |
12 | |
23 | |
13 | # work around Tk bug until it has been fixed. |
24 | # work around Tk bug until it has been fixed. |
14 | my $timer = AnyEvent->timer (after => 2, cb => sub { }); |
25 | #my $timer = AnyEvent->timer (after => 2, cb => sub { }); |
15 | |
26 | |
16 | my $cv = AnyEvent->condvar; |
27 | my $cv = AnyEvent->condvar; |
17 | |
28 | |
18 | unless ($pid) { |
29 | unless ($pid) { |
19 | print "ok 2\n"; |
30 | print "ok 2\n"; |
20 | exit 3; |
31 | exit 3; |
21 | } |
32 | } |
22 | |
33 | |
23 | my $w = AnyEvent->child (pid => $pid, cb => sub { |
34 | my $w = AnyEvent->child (pid => $pid, cb => sub { |
24 | print $pid == $_[0] ? "" : "not ", "ok 3\n"; |
35 | print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n"; |
25 | print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4\n"; |
36 | print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n"; |
26 | $cv->broadcast; |
37 | $cv->broadcast; |
27 | }); |
38 | }); |
28 | |
39 | |
29 | $cv->wait; |
40 | $cv->wait; |
30 | |
41 | |
31 | my $pid2 = fork || exit 7; |
42 | my $pid2 = fork || exit 7; |
32 | |
43 | |
33 | my $cv2 = AnyEvent->condvar; |
44 | my $cv2 = AnyEvent->condvar; |
34 | |
45 | |
35 | my $w2 = AnyEvent->child (pid => 0, cb => sub { |
46 | my $w2 = AnyEvent->child (pid => 0, cb => sub { |
36 | print $pid2 == $_[0] ? "" : "not ", "ok 5\n"; |
47 | print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n"; |
37 | print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6\n"; |
48 | print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n"; |
38 | $cv2->broadcast; |
49 | $cv2->broadcast; |
|
|
50 | }); |
|
|
51 | |
|
|
52 | my $error = AnyEvent->timer (after => 5, cb => sub { |
|
|
53 | print <<EOF; |
|
|
54 | Bail out! No child exit detected. This is either a bug in AnyEvent or a bug in your Perl (mostly some windows distributions suffer from that): child watchers might not work properly on this platform. You can force installation of this module if you do not rely on child watchers, or you could upgrade to a working version of Perl for your platform.\n"; |
|
|
55 | EOF |
|
|
56 | exit 0; |
39 | }); |
57 | }); |
40 | |
58 | |
41 | $cv2->wait; |
59 | $cv2->wait; |
42 | |
60 | |
43 | print "ok 7\n"; |
61 | print "ok 7\n"; |