diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-10-27 18:36:47 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-10-27 18:36:47 (GMT) |
commit | f829d1f551f75005d78dec303957808e7833964e (patch) | |
tree | edff8783850bec5d59e0d6207435336570250886 /Lib/test | |
parent | abc9f7038154c5bd5d3a6042ab972f2db0fbc241 (diff) | |
download | cpython-f829d1f551f75005d78dec303957808e7833964e.zip cpython-f829d1f551f75005d78dec303957808e7833964e.tar.gz cpython-f829d1f551f75005d78dec303957808e7833964e.tar.bz2 |
Suppress transient refleaks in test_asyncore
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_asyncore.py | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py index ce835aa..1a54ce5 100644 --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -319,40 +319,44 @@ class DispatcherWithSendTests(unittest.TestCase): def tearDown(self): asyncore.close_all() + @test_support.reap_threads def test_send(self): - self.evt = threading.Event() - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.settimeout(3) - self.port = test_support.bind_port(self.sock) + evt = threading.Event() + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.settimeout(3) + port = test_support.bind_port(sock) cap = StringIO() - args = (self.evt, cap, self.sock) - threading.Thread(target=capture_server, args=args).start() - - # wait a little longer for the server to initialize (it sometimes - # refuses connections on slow machines without this wait) - time.sleep(0.2) + args = (evt, cap, sock) + t = threading.Thread(target=capture_server, args=args) + t.start() + try: + # wait a little longer for the server to initialize (it sometimes + # refuses connections on slow machines without this wait) + time.sleep(0.2) - data = "Suppose there isn't a 16-ton weight?" - d = dispatcherwithsend_noread() - d.create_socket(socket.AF_INET, socket.SOCK_STREAM) - d.connect((HOST, self.port)) + data = "Suppose there isn't a 16-ton weight?" + d = dispatcherwithsend_noread() + d.create_socket(socket.AF_INET, socket.SOCK_STREAM) + d.connect((HOST, port)) - # give time for socket to connect - time.sleep(0.1) + # give time for socket to connect + time.sleep(0.1) - d.send(data) - d.send(data) - d.send('\n') + d.send(data) + d.send(data) + d.send('\n') - n = 1000 - while d.out_buffer and n > 0: - asyncore.poll() - n -= 1 + n = 1000 + while d.out_buffer and n > 0: + asyncore.poll() + n -= 1 - self.evt.wait() + evt.wait() - self.assertEqual(cap.getvalue(), data*2) + self.assertEqual(cap.getvalue(), data*2) + finally: + t.join() class DispatcherWithSendTests_UsePoll(DispatcherWithSendTests): |