mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
Issue #19305: try to fix sporadic test_asyncio failure on FreeBSD 10.0
This commit is contained in:
parent
0d9eefda34
commit
d20afad7d4
2 changed files with 20 additions and 2 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
import unittest.mock
|
import unittest.mock
|
||||||
from wsgiref.simple_server import make_server, WSGIRequestHandler, WSGIServer
|
from wsgiref.simple_server import make_server, WSGIRequestHandler, WSGIServer
|
||||||
|
|
@ -46,6 +47,20 @@ def once():
|
||||||
gen.close()
|
gen.close()
|
||||||
|
|
||||||
|
|
||||||
|
def run_until(loop, pred, timeout=None):
|
||||||
|
if timeout is not None:
|
||||||
|
deadline = time.time() + timeout
|
||||||
|
while not pred():
|
||||||
|
if timeout is not None:
|
||||||
|
timeout = deadline - time.time()
|
||||||
|
if timeout <= 0:
|
||||||
|
return False
|
||||||
|
loop.run_until_complete(tasks.sleep(timeout, loop=loop))
|
||||||
|
else:
|
||||||
|
run_briefly(loop)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def run_once(loop):
|
def run_once(loop):
|
||||||
"""loop.stop() schedules _raise_stop_error()
|
"""loop.stop() schedules _raise_stop_error()
|
||||||
and run_forever() runs until _raise_stop_error() callback.
|
and run_forever() runs until _raise_stop_error() callback.
|
||||||
|
|
|
||||||
|
|
@ -558,13 +558,14 @@ def factory():
|
||||||
self.assertEqual(host, '0.0.0.0')
|
self.assertEqual(host, '0.0.0.0')
|
||||||
client = socket.socket()
|
client = socket.socket()
|
||||||
client.connect(('127.0.0.1', port))
|
client.connect(('127.0.0.1', port))
|
||||||
client.send(b'xxx')
|
client.sendall(b'xxx')
|
||||||
test_utils.run_briefly(self.loop)
|
test_utils.run_briefly(self.loop)
|
||||||
self.assertIsInstance(proto, MyProto)
|
self.assertIsInstance(proto, MyProto)
|
||||||
self.assertEqual('INITIAL', proto.state)
|
self.assertEqual('INITIAL', proto.state)
|
||||||
test_utils.run_briefly(self.loop)
|
test_utils.run_briefly(self.loop)
|
||||||
self.assertEqual('CONNECTED', proto.state)
|
self.assertEqual('CONNECTED', proto.state)
|
||||||
test_utils.run_briefly(self.loop) # windows iocp
|
test_utils.run_until(self.loop, lambda: proto.nbytes > 0,
|
||||||
|
timeout=10)
|
||||||
self.assertEqual(3, proto.nbytes)
|
self.assertEqual(3, proto.nbytes)
|
||||||
|
|
||||||
# extra info is available
|
# extra info is available
|
||||||
|
|
@ -623,6 +624,8 @@ def factory():
|
||||||
self.assertIsInstance(proto, MyProto)
|
self.assertIsInstance(proto, MyProto)
|
||||||
test_utils.run_briefly(self.loop)
|
test_utils.run_briefly(self.loop)
|
||||||
self.assertEqual('CONNECTED', proto.state)
|
self.assertEqual('CONNECTED', proto.state)
|
||||||
|
test_utils.run_until(self.loop, lambda: proto.nbytes > 0,
|
||||||
|
timeout=10)
|
||||||
self.assertEqual(3, proto.nbytes)
|
self.assertEqual(3, proto.nbytes)
|
||||||
|
|
||||||
# extra info is available
|
# extra info is available
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue