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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines