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.6 by root, Fri Aug 26 03:33:59 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";
8 26
9my ($a, $b) = AnyEvent::Util::portable_socketpair; 27my ($a, $b) = AnyEvent::Util::portable_socketpair;
10 28
11# I/O write 29# I/O write
12{ 30{
13 my $cv = AE::cv; 31 my $cv = AE::cv;
14 my $wt = AE::timer 0.1, 0, $cv; 32 my $wt = AE::timer 1, 0, $cv;
15 my $s = 0; 33 my $s = 0;
16 34
17 $cv->begin; my $wa = AE::io $a, 1, sub { $cv->end; $s |= 1 }; 35 $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 }; 36 $cv->begin; my $wb = AE::io $a, 1, sub { $cv->end; $s |= 2 };
19 37
23} 41}
24 42
25# I/O read 43# I/O read
26{ 44{
27 my $cv = AE::cv; 45 my $cv = AE::cv;
28 my $wt = AE::timer 0.1, 0, $cv; 46 my $wt = AE::timer 0.01, 0, $cv;
29 my $s = 0; 47 my $s = 0;
30 48
31 my $wa = AE::io $a, 0, sub { $cv->end; $s |= 1 }; 49 my $wa = AE::io $a, 0, sub { $cv->end; $s |= 1 };
32 my $wb = AE::io $a, 0, sub { $cv->end; $s |= 2 }; 50 my $wb = AE::io $a, 0, sub { $cv->end; $s |= 2 };
33 51
36 print $s == 0 ? "" : "not ", "ok 3 # $s\n"; 54 print $s == 0 ? "" : "not ", "ok 3 # $s\n";
37 55
38 syswrite $b, "x"; 56 syswrite $b, "x";
39 57
40 $cv = AE::cv; 58 $cv = AE::cv;
41 $wt = AE::timer 0.1, 0, $cv; 59 $wt = AE::timer 1, 0, $cv;
42 60
43 $s = 0; 61 $s = 0;
44 $cv->begin; 62 $cv->begin;
45 $cv->begin; 63 $cv->begin;
46 $cv->recv; 64 $cv->recv;
48 print $s == 3 ? "" : "not ", "ok 4 # $s\n"; 66 print $s == 3 ? "" : "not ", "ok 4 # $s\n";
49 67
50 sysread $a, my $dummy, 1; 68 sysread $a, my $dummy, 1;
51 69
52 $cv = AE::cv; 70 $cv = AE::cv;
53 $wt = AE::timer 0.1, 0, $cv; 71 $wt = AE::timer 0.01, 0, $cv;
54 72
55 $s = 0; 73 $s = 0;
56 $cv->recv; 74 $cv->recv;
57 75
58 print $s == 0 ? "" : "not ", "ok 5 # $s\n"; 76 print $s == 0 ? "" : "not ", "ok 5 # $s\n";
59} 77}
60 78
61# signal 79# signal
62{ 80{
63 my $cv = AE::cv; 81 my $cv = AE::cv;
64 my $wt = AE::timer 0.1, 0, $cv; 82 my $wt = AE::timer 0.01, 0, $cv;
65 my $s = 0; 83 my $s = 0;
66 84
67 $cv->begin; my $wa = AE::signal INT => sub { $cv->end; $s |= 1 }; 85 $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 }; 86 $cv->begin; my $wb = AE::signal INT => sub { $cv->end; $s |= 2 };
69 87
72 print $s == 0 ? "" : "not ", "ok 6 # $s\n"; 90 print $s == 0 ? "" : "not ", "ok 6 # $s\n";
73 91
74 kill INT => $$; 92 kill INT => $$;
75 93
76 $cv = AE::cv; 94 $cv = AE::cv;
77 $wt = AE::timer 0.1, 0, $cv; 95 $wt = AE::timer 0.01, 0, $cv;
78 96
79 $s = 0; 97 $s = 0;
80 $cv->recv; 98 $cv->recv;
81 99
82 print $s == 3 ? "" : "not ", "ok 7 # $s\n"; 100 print $s == 3 ? "" : "not ", "ok 7 # $s\n";
83 101
84 $cv = AE::cv; 102 $cv = AE::cv;
85 $wt = AE::timer 0.1, 0, $cv; 103 $wt = AE::timer 0.01, 0, $cv;
86 104
87 $s = 0; 105 $s = 0;
88 $cv->recv; 106 $cv->recv;
89 107
90 print $s == 0 ? "" : "not ", "ok 8 # $s\n"; 108 print $s == 0 ? "" : "not ", "ok 8 # $s\n";
93$AnyEvent::MAX_SIGNAL_LATENCY = 0.2; 111$AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
94 112
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