15
15
16
16
HOST = support .HOST
17
17
SERVER_QUIT = b'QUIT\n '
18
+ TIMEOUT = 3.0
18
19
19
20
if threading :
20
21
class echo_server (threading .Thread ):
@@ -123,7 +124,9 @@ def line_terminator_check(self, term, server_chunk):
123
124
c .push (b"I'm not dead yet!" + term )
124
125
c .push (SERVER_QUIT )
125
126
asyncore .loop (use_poll = self .usepoll , count = 300 , timeout = .01 )
126
- s .join ()
127
+ s .join (timeout = TIMEOUT )
128
+ if s .is_alive ():
129
+ self .fail ("join() timed out" )
127
130
128
131
self .assertEqual (c .contents , [b"hello world" , b"I'm not dead yet!" ])
129
132
@@ -154,7 +157,9 @@ def numeric_terminator_check(self, termlen):
154
157
c .push (data )
155
158
c .push (SERVER_QUIT )
156
159
asyncore .loop (use_poll = self .usepoll , count = 300 , timeout = .01 )
157
- s .join ()
160
+ s .join (timeout = TIMEOUT )
161
+ if s .is_alive ():
162
+ self .fail ("join() timed out" )
158
163
159
164
self .assertEqual (c .contents , [data [:termlen ]])
160
165
@@ -174,7 +179,9 @@ def test_none_terminator(self):
174
179
c .push (data )
175
180
c .push (SERVER_QUIT )
176
181
asyncore .loop (use_poll = self .usepoll , count = 300 , timeout = .01 )
177
- s .join ()
182
+ s .join (timeout = TIMEOUT )
183
+ if s .is_alive ():
184
+ self .fail ("join() timed out" )
178
185
179
186
self .assertEqual (c .contents , [])
180
187
self .assertEqual (c .buffer , data )
@@ -186,7 +193,9 @@ def test_simple_producer(self):
186
193
p = asynchat .simple_producer (data + SERVER_QUIT , buffer_size = 8 )
187
194
c .push_with_producer (p )
188
195
asyncore .loop (use_poll = self .usepoll , count = 300 , timeout = .01 )
189
- s .join ()
196
+ s .join (timeout = TIMEOUT )
197
+ if s .is_alive ():
198
+ self .fail ("join() timed out" )
190
199
191
200
self .assertEqual (c .contents , [b"hello world" , b"I'm not dead yet!" ])
192
201
@@ -196,7 +205,9 @@ def test_string_producer(self):
196
205
data = b"hello world\n I'm not dead yet!\n "
197
206
c .push_with_producer (data + SERVER_QUIT )
198
207
asyncore .loop (use_poll = self .usepoll , count = 300 , timeout = .01 )
199
- s .join ()
208
+ s .join (timeout = TIMEOUT )
209
+ if s .is_alive ():
210
+ self .fail ("join() timed out" )
200
211
201
212
self .assertEqual (c .contents , [b"hello world" , b"I'm not dead yet!" ])
202
213
@@ -207,7 +218,9 @@ def test_empty_line(self):
207
218
c .push (b"hello world\n \n I'm not dead yet!\n " )
208
219
c .push (SERVER_QUIT )
209
220
asyncore .loop (use_poll = self .usepoll , count = 300 , timeout = .01 )
210
- s .join ()
221
+ s .join (timeout = TIMEOUT )
222
+ if s .is_alive ():
223
+ self .fail ("join() timed out" )
211
224
212
225
self .assertEqual (c .contents ,
213
226
[b"hello world" , b"" , b"I'm not dead yet!" ])
@@ -226,7 +239,9 @@ def test_close_when_done(self):
226
239
# where the server echoes all of its data before we can check that it
227
240
# got any down below.
228
241
s .start_resend_event .set ()
229
- s .join ()
242
+ s .join (timeout = TIMEOUT )
243
+ if s .is_alive ():
244
+ self .fail ("join() timed out" )
230
245
231
246
self .assertEqual (c .contents , [])
232
247
# the server might have been able to send a byte or two back, but this
0 commit comments