ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/03_child.t
Revision: 1.10
Committed: Fri May 23 16:36:02 2008 UTC (16 years, 1 month ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_151, rel-4_152, rel-4_04, rel-4_23, rel-4_21, rel-4_352, rel-4_351, rel-4_14, rel-4_15, rel-4_13, rel-4_331, rel-4_231, rel-4_233, rel-4_232, rel-4_234, rel-4_4, rel-4_0, rel-4_05, rel-4_12, rel-4_11, rel-4_22, rel-4_161, rel-4_160, rel-4_1, rel-4_2, rel-4_3, rel-4_31, rel-4_32, rel-4_33, rel-4_34, rel-4_35, rel-4_03
Changes since 1.9: +17 -9 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 $|=1;
2 root 1.10
3     BEGIN {
4     # check for broken perls
5     if ($^O =~ /mswin32/i) {
6     my $ok;
7     local $SIG{CHLD} = sub { $ok = 1 };
8     kill 'CHLD', 0;
9    
10     unless ($ok) {
11     print <<EOF;
12     1..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.
13     EOF
14     exit 0;
15     }
16     }
17     }
18    
19 root 1.8 BEGIN {
20     print "1..7\n"
21     }
22 root 1.1
23     use AnyEvent;
24 root 1.5 use AnyEvent::Impl::Perl;
25 root 1.1
26     print "ok 1\n";
27    
28 root 1.9 AnyEvent::detect; # force-load event model
29    
30 root 1.1 my $pid = fork;
31    
32     defined $pid or die "unable to fork";
33    
34     # work around Tk bug until it has been fixed.
35 root 1.6 #my $timer = AnyEvent->timer (after => 2, cb => sub { });
36 root 1.1
37     my $cv = AnyEvent->condvar;
38    
39     unless ($pid) {
40     print "ok 2\n";
41     exit 3;
42     }
43    
44     my $w = AnyEvent->child (pid => $pid, cb => sub {
45 root 1.7 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n";
46     print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n";
47 root 1.1 $cv->broadcast;
48     });
49    
50     $cv->wait;
51    
52 root 1.3 my $pid2 = fork || exit 7;
53 root 1.2
54     my $cv2 = AnyEvent->condvar;
55    
56     my $w2 = AnyEvent->child (pid => 0, cb => sub {
57 root 1.7 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n";
58     print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n";
59 root 1.2 $cv2->broadcast;
60     });
61    
62 root 1.8 my $error = AnyEvent->timer (after => 5, cb => sub {
63     print <<EOF;
64     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";
65     EOF
66     exit 0;
67     });
68    
69 root 1.2 $cv2->wait;
70    
71 root 1.3 print "ok 7\n";
72 root 1.1
73    
74    
75