[Python-checkins] r46994 - sandbox/trunk/pdb/test/tcptest.py
matt.fleming
python-checkins at python.org
Fri Jun 16 22:01:59 CEST 2006
Author: matt.fleming
Date: Fri Jun 16 22:01:58 2006
New Revision: 46994
Modified:
sandbox/trunk/pdb/test/tcptest.py
Log:
Stop using a Timer object and just repeatedly try to connect. Tests should
pass faster now.
Modified: sandbox/trunk/pdb/test/tcptest.py
==============================================================================
--- sandbox/trunk/pdb/test/tcptest.py (original)
+++ sandbox/trunk/pdb/test/tcptest.py Fri Jun 16 22:01:58 2006
@@ -1,7 +1,11 @@
#!/usr/bin/env python
-import os
+
+# This unit test doesn't use any of the debugger code. It is meant solely
+# to test the connection classes.
+
import sys
import socket
+import thread
import threading
import unittest
@@ -10,20 +14,32 @@
sys.path.append("..")
from mconnection import MServerConnectionTCP, MClientConnectionTCP
+# Try to connect the client to addr either until we've tried MAXTRIES
+# times or until it succeeds.
+MAXTRIES = 100
+def repeatedConnect(client, addr):
+ for i in range(MAXTRIES):
+ try:
+ client.connect(addr)
+ # The _sock variable appears when there's a connection
+ if client._sock: break
+ except socket.error:
+ pass
+
class TestTCPConnections(unittest.TestCase):
- def testClientConnectAndRead(self):
+ def setUp(self):
self.server = MServerConnectionTCP()
self.client = MClientConnectionTCP()
- # Create a new thread for the client and delay for 3 seconds
- t = threading.Timer(3.0, self.client.connect, [__addr__])
- t.start()
- # Start server, which waits for a connection. self.client will connect
- # in a few seconds
+
+ def testClientConnectAndRead(self):
+ t_id = thread.start_new_thread(repeatedConnect, (self.client,__addr__))
self.server.connect(__addr__)
self.server.write("good")
line = self.client.readline()
self.assertEqual("good", line, "Could not read from server")
+
+ def tearDown(self):
self.server.disconnect()
self.client.disconnect()
More information about the Python-checkins
mailing list