ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/03_child.t
(Generate patch)

Comparing AnyEvent/t/03_child.t (file contents):
Revision 1.7 by root, Sun Nov 25 14:08:12 2007 UTC vs.
Revision 1.15 by root, Sat Jul 18 00:05:29 2009 UTC

1$|=1; 1use POSIX ();
2BEGIN { print "1..7\n" }
3 2
4use AnyEvent; 3use AnyEvent;
5use AnyEvent::Impl::Perl; 4use AnyEvent::Impl::Perl;
6 5
6BEGIN {
7 # check for broken perls
8 if ($^O =~ /mswin32/i) {
9 my $ok;
10 local $SIG{CHLD} = sub { $ok = 1 };
11 kill 'CHLD', 0;
12
13 unless ($ok) {
14 print <<EOF;
151..0 # Your perl interpreter is badly BROKEN. Child watchers will not work, ever. Try upgrading to a newer perl or a working perl (cygwin's perl is known to work). If that is not an option, you should be able to use the remaining functionality of AnyEvent, but child watchers WILL NOT WORK.
16EOF
17 exit 0;
18 }
19 }
20}
21
22$| = 1; print "1..7\n";
23
24$AnyEvent::MAX_SIGNAL_LATENCY = 1;
25
7print "ok 1\n"; 26print "ok 1\n";
27
28AnyEvent::detect; # force-load event model
8 29
9my $pid = fork; 30my $pid = fork;
10 31
11defined $pid or die "unable to fork"; 32defined $pid or die "unable to fork";
12 33
15 36
16my $cv = AnyEvent->condvar; 37my $cv = AnyEvent->condvar;
17 38
18unless ($pid) { 39unless ($pid) {
19 print "ok 2\n"; 40 print "ok 2\n";
20 exit 3; 41 POSIX::_exit 3;
21} 42}
22 43
23my $w = AnyEvent->child (pid => $pid, cb => sub { 44my $w = AnyEvent->child (pid => $pid, cb => sub {
24 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n"; 45 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n";
25 print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n"; 46 print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n";
26 $cv->broadcast; 47 $cv->broadcast;
27}); 48});
28 49
29$cv->wait; 50$cv->wait;
30 51
31my $pid2 = fork || exit 7; 52my $pid2 = fork || POSIX::_exit 7;
32 53
33my $cv2 = AnyEvent->condvar; 54my $cv2 = AnyEvent->condvar;
34 55
35my $w2 = AnyEvent->child (pid => 0, cb => sub { 56my $w2 = AnyEvent->child (pid => 0, cb => sub {
36 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n"; 57 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n";
37 print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n"; 58 print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n";
38 $cv2->broadcast; 59 $cv2->broadcast;
39}); 60});
40 61
62my $error = AnyEvent->timer (after => 5, cb => sub {
63 print <<EOF;
64Bail 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";
65EOF
66 exit 0;
67});
68
41$cv2->wait; 69$cv2->wait;
42 70
43print "ok 7\n"; 71print "ok 7\n";
44 72
45 73

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines