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.9 by root, Fri Apr 25 13:32:39 2008 UTC vs.
Revision 1.13 by root, Thu Jul 9 22:37:53 2009 UTC

1$|=1;
2BEGIN { 1BEGIN {
2 # check for broken perls
3 if ($^O =~ /mswin32/i) {
4 my $ok;
5 local $SIG{CHLD} = sub { $ok = 1 };
6 kill 'CHLD', 0;
7
8 unless ($ok) {
9 print <<EOF;
101..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.
11EOF
12 exit 0;
13 }
14 }
15}
16
17BEGIN {
18 $|=1;
3 print "1..7\n" 19 print "1..7\n"
4} 20}
5 21
22use POSIX ();
23
6use AnyEvent; 24use AnyEvent;
7use AnyEvent::Impl::Perl; 25use AnyEvent::Impl::Perl;
8
9print STDERR <<EOF;
10
11If the following test hangs for a long time you either found a bug in
12AnyEvent or, more likely, you have a defective perl (most windows perl
13distros are broken, cygwin perl works). If you do not rely on child
14handlers you can force the installation of this module and the rest will
15likely work. Otherwise upgrading to a working perl is recommended.
16EOF
17 26
18print "ok 1\n"; 27print "ok 1\n";
19 28
20AnyEvent::detect; # force-load event model 29AnyEvent::detect; # force-load event model
21 30
28 37
29my $cv = AnyEvent->condvar; 38my $cv = AnyEvent->condvar;
30 39
31unless ($pid) { 40unless ($pid) {
32 print "ok 2\n"; 41 print "ok 2\n";
33 exit 3; 42 POSIX::_exit 3;
34} 43}
35 44
36my $w = AnyEvent->child (pid => $pid, cb => sub { 45my $w = AnyEvent->child (pid => $pid, cb => sub {
37 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n"; 46 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n";
38 print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n"; 47 print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n";
39 $cv->broadcast; 48 $cv->broadcast;
40}); 49});
41 50
42$cv->wait; 51$cv->wait;
43 52
44my $pid2 = fork || exit 7; 53my $pid2 = fork || POSIX::_exit 7;
45 54
46my $cv2 = AnyEvent->condvar; 55my $cv2 = AnyEvent->condvar;
47 56
48my $w2 = AnyEvent->child (pid => 0, cb => sub { 57my $w2 = AnyEvent->child (pid => 0, cb => sub {
49 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n"; 58 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n";
50 print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n"; 59 print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n";
51 $cv2->broadcast; 60 $cv2->broadcast;
52}); 61});
53 62
54my $error = AnyEvent->timer (after => 5, cb => sub { 63my $error = AnyEvent->timer (after => 15, cb => sub {
55 print <<EOF; 64 print <<EOF;
56Bail 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"; 65Bail 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";
57EOF 66EOF
58 exit 0; 67 exit 0;
68});
69
70my $inter = AnyEvent->timer (after => 14, cb => sub {
71 print "not ok 5 # inter\n";
72 print "not ok 6 # inter\n";
73 $cv2->send;
59}); 74});
60 75
61$cv2->wait; 76$cv2->wait;
62 77
63print "ok 7\n"; 78print "ok 7\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines