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

Comparing AnyEvent/t/09_multi.t (file contents):
Revision 1.2 by root, Tue Aug 2 22:07:16 2011 UTC vs.
Revision 1.9 by root, Sat Oct 1 22:48:36 2011 UTC

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 # SKIP 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
17$^W = 0; # 5.8.6 bugs
18
1use AnyEvent; 19use AnyEvent;
2use AnyEvent::Util; 20use AnyEvent::Util;
3BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} } 21BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} }
4 22
5$| = 1; print "1..14\n"; 23$| = 1; print "1..15\n";
6 24
7print "ok 1\n"; 25print "ok 1\n";
26
27$AnyEvent::MAX_SIGNAL_LATENCY = 0.05;
8 28
9my ($a, $b) = AnyEvent::Util::portable_socketpair; 29my ($a, $b) = AnyEvent::Util::portable_socketpair;
10 30
11# I/O write 31# I/O write
12{ 32{
13 my $cv = AE::cv; 33 my $cv = AE::cv;
14 my $wt = AE::timer 0.1, 0, $cv; 34 my $wt = AE::timer 1, 0, $cv;
15 my $s = 0; 35 my $s = 0;
16 36
17 $cv->begin; my $wa = AE::io $a, 1, sub { $cv->end; $s |= 1 }; 37 $cv->begin; my $wa = AE::io $a, 1, sub { $cv->end; $s |= 1 };
18 $cv->begin; my $wb = AE::io $a, 1, sub { $cv->end; $s |= 2 }; 38 $cv->begin; my $wb = AE::io $a, 1, sub { $cv->end; $s |= 2 };
19 39
23} 43}
24 44
25# I/O read 45# I/O read
26{ 46{
27 my $cv = AE::cv; 47 my $cv = AE::cv;
28 my $wt = AE::timer 0.1, 0, $cv; 48 my $wt = AE::timer 0.01, 0, $cv;
29 my $s = 0; 49 my $s = 0;
30 50
31 my $wa = AE::io $a, 0, sub { $cv->end; $s |= 1 }; 51 my $wa = AE::io $a, 0, sub { $cv->end; $s |= 1 };
32 my $wb = AE::io $a, 0, sub { $cv->end; $s |= 2 }; 52 my $wb = AE::io $a, 0, sub { $cv->end; $s |= 2 };
33 53
36 print $s == 0 ? "" : "not ", "ok 3 # $s\n"; 56 print $s == 0 ? "" : "not ", "ok 3 # $s\n";
37 57
38 syswrite $b, "x"; 58 syswrite $b, "x";
39 59
40 $cv = AE::cv; 60 $cv = AE::cv;
41 $wt = AE::timer 0.1, 0, $cv; 61 $wt = AE::timer 1, 0, $cv;
42 62
43 $s = 0; 63 $s = 0;
44 $cv->begin; 64 $cv->begin;
45 $cv->begin; 65 $cv->begin;
46 $cv->recv; 66 $cv->recv;
48 print $s == 3 ? "" : "not ", "ok 4 # $s\n"; 68 print $s == 3 ? "" : "not ", "ok 4 # $s\n";
49 69
50 sysread $a, my $dummy, 1; 70 sysread $a, my $dummy, 1;
51 71
52 $cv = AE::cv; 72 $cv = AE::cv;
53 $wt = AE::timer 0.1, 0, $cv; 73 $wt = AE::timer 0.01, 0, $cv;
54 74
55 $s = 0; 75 $s = 0;
56 $cv->recv; 76 $cv->recv;
57 77
58 print $s == 0 ? "" : "not ", "ok 5 # $s\n"; 78 print $s == 0 ? "" : "not ", "ok 5 # $s\n";
59} 79}
60 80
61# signal 81# signal
62{ 82{
63 my $cv = AE::cv; 83 my $cv = AE::cv;
64 my $wt = AE::timer 0.1, 0, $cv; 84 my $wt = AE::timer 0.01, 0, $cv;
65 my $s = 0; 85 my $s = 0;
66 86
67 $cv->begin; my $wa = AE::signal INT => sub { $cv->end; $s |= 1 }; 87 $cv->begin; my $wa = AE::signal INT => sub { $cv->end; $s |= 1 };
68 $cv->begin; my $wb = AE::signal INT => sub { $cv->end; $s |= 2 }; 88 $cv->begin; my $wb = AE::signal INT => sub { $cv->end; $s |= 2 };
69 89
72 print $s == 0 ? "" : "not ", "ok 6 # $s\n"; 92 print $s == 0 ? "" : "not ", "ok 6 # $s\n";
73 93
74 kill INT => $$; 94 kill INT => $$;
75 95
76 $cv = AE::cv; 96 $cv = AE::cv;
77 $wt = AE::timer 0.1, 0, $cv; 97 $wt = AE::timer 0.2, 0, $cv; # maybe OS X needs more time here? or maybe some buggy arm kernel?
78 98
79 $s = 0; 99 $s = 0;
80 $cv->recv; 100 $cv->recv;
81 101
82 print $s == 3 ? "" : "not ", "ok 7 # $s\n"; 102 print $s == 3 ? "" : "not ", "ok 7 # $s\n";
83 103
84 $cv = AE::cv; 104 $cv = AE::cv;
85 $wt = AE::timer 0.1, 0, $cv; 105 $wt = AE::timer 0.01, 0, $cv;
86 106
87 $s = 0; 107 $s = 0;
88 $cv->recv; 108 $cv->recv;
89 109
90 print $s == 0 ? "" : "not ", "ok 8 # $s\n"; 110 print $s == 0 ? "" : "not ", "ok 8 # $s\n";
91} 111}
92 112
93$AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
94
95# child 113# child
96{ 114{
97 my $cv = AE::cv; 115 my $cv = AE::cv;
98 my $wt = AE::timer 0.1, 0, $cv; 116 my $wt = AE::timer 0.01, 0, $cv;
99 my $s = 0; 117 my $s = 0;
100 118
101 my $pid = fork; 119 my $pid = fork;
102 120
103 unless ($pid) { 121 unless ($pid) {
115 print $s == 0 ? "" : "not ", "ok 9 # $s\n"; 133 print $s == 0 ? "" : "not ", "ok 9 # $s\n";
116 134
117 kill 9, $pid; 135 kill 9, $pid;
118 136
119 $cv = AE::cv; 137 $cv = AE::cv;
120 $wt = AE::timer 0.1, 0, $cv; 138 $wt = AE::timer 0.2, 0, $cv; # cygwin needs ages for this
121 139
122 $s = 0; 140 $s = 0;
123 $cv->recv; 141 $cv->recv;
124 142
125 print $s == 3 ? "" : "not ", "ok 10 # $s\n"; 143 print $s == 3 ? "" : "not ", "ok 10 # $s\n";
126 print $apid == $pid && $bpid == $pid ? "" : "not ", "ok 11 # $apid == $bpid == $pid\n"; 144 print $apid == $pid && $bpid == $pid ? "" : "not ", "ok 11 # $apid == $bpid == $pid\n";
127 print $astatus == 9 && $bstatus == 9 ? "" : "not ", "ok 12 # $astatus == $bstatus == 9\n"; 145 print $astatus == 9 && $bstatus == 9 ? "" : "not ", "ok 12 # $astatus == $bstatus == 9\n";
128 146
129 $cv = AE::cv; 147 $cv = AE::cv;
130 $wt = AE::timer 0.1, 0, $cv; 148 $wt = AE::timer 0.01, 0, $cv;
131 149
132 $s = 0; 150 $s = 0;
133 $cv->recv; 151 $cv->recv;
134 152
135 print $s == 0 ? "" : "not ", "ok 13 # $s\n"; 153 print $s == 0 ? "" : "not ", "ok 13 # $s\n";
136} 154}
137 155
156# timers (don't laugh, some event loops are more broken...)
157{
158 my $cv = AE::cv;
159 my $wt = AE::timer 1, 0, $cv;
160 my $s = 0;
161
162 $cv->begin; my $wa = AE::timer 0 , 0, sub { $cv->end; $s |= 1 };
163 $cv->begin; my $wb = AE::timer 0 , 0, sub { $cv->end; $s |= 2 };
164 $cv->begin; my $wc = AE::timer 0.01, 0, sub { $cv->end; $s |= 4 };
165
166 $cv->recv;
167
168 print $s == 7 ? "" : "not ", "ok 14 # $s\n";
169}
170
138print "ok 14\n"; 171print "ok 15\n";
139 172
140exit 0; 173exit 0;
141 174

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines