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.8 by root, Tue Apr 22 05:12:19 2008 UTC vs.
Revision 1.15 by root, Sat Jul 18 00:05:29 2009 UTC

1$|=1; 1use POSIX ();
2BEGIN {
3 print "1..7\n"
4}
5 2
6use AnyEvent; 3use AnyEvent;
7use AnyEvent::Impl::Perl; 4use AnyEvent::Impl::Perl;
8 5
9print STDERR <<EOF; 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;
10 12
11If the following test hangs for a long time you either found a bug in 13 unless ($ok) {
12AnyEvent or, more likely, you have a defective perl (most windows perl 14 print <<EOF;
13distros are broken, cygwin perl works). If you do not rely on child 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.
14handlers you can force the installation of this module and the rest will
15likely work. Otherwise upgrading to a working perl is recommended.
16EOF 16EOF
17 exit 0;
18 }
19 }
20}
21
22$| = 1; print "1..7\n";
23
24$AnyEvent::MAX_SIGNAL_LATENCY = 1;
17 25
18print "ok 1\n"; 26print "ok 1\n";
27
28AnyEvent::detect; # force-load event model
19 29
20my $pid = fork; 30my $pid = fork;
21 31
22defined $pid or die "unable to fork"; 32defined $pid or die "unable to fork";
23 33
26 36
27my $cv = AnyEvent->condvar; 37my $cv = AnyEvent->condvar;
28 38
29unless ($pid) { 39unless ($pid) {
30 print "ok 2\n"; 40 print "ok 2\n";
31 exit 3; 41 POSIX::_exit 3;
32} 42}
33 43
34my $w = AnyEvent->child (pid => $pid, cb => sub { 44my $w = AnyEvent->child (pid => $pid, cb => sub {
35 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n"; 45 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n";
36 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";
37 $cv->broadcast; 47 $cv->broadcast;
38}); 48});
39 49
40$cv->wait; 50$cv->wait;
41 51
42my $pid2 = fork || exit 7; 52my $pid2 = fork || POSIX::_exit 7;
43 53
44my $cv2 = AnyEvent->condvar; 54my $cv2 = AnyEvent->condvar;
45 55
46my $w2 = AnyEvent->child (pid => 0, cb => sub { 56my $w2 = AnyEvent->child (pid => 0, cb => sub {
47 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n"; 57 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines