[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/tests - testHTTPServer.py:1.1.2.9

Shane Hathaway shane@cvs.zope.org
Thu, 10 Jan 2002 17:29:03 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Server/tests
In directory cvs.zope.org:/tmp/cvs-serv27710/Server/tests

Modified Files:
      Tag: Zope-3x-branch
	testHTTPServer.py 
Log Message:
Fixed failed test.  testHTTPServer.py has a check to ensure that all opened
channels on the server end get closed at the end of the test, but since
select triggers are also channels, the check would fail if the select
trigger happened to be created in the middle of a test.  Now we just
make sure the select trigger exists before starting the test.


=== Zope3/lib/python/Zope/Server/tests/testHTTPServer.py 1.1.2.8 => 1.1.2.9 ===
 import socket
 
+from medusa.thread import select_trigger
 from threading import Thread
 from Zope.Server.TaskThreads import ThreadedTaskDispatcher
 from Zope.Server.HTTPServer import http_task, http_channel, http_server
@@ -71,13 +72,19 @@
         pass
 
 
+def createSelectTrigger():
+    # Creates the default select trigger if it doesn't yet exist.
+    if select_trigger.the_trigger is None:
+        select_trigger.the_trigger = select_trigger.trigger()
+
 
 class Tests(unittest.TestCase):
 
     def setUp(self):
         td.setThreadCount(4)
-        # Bind to any port on localhost.
+        createSelectTrigger()
         self.orig_map_size = len(socket_map)
+        # Bind to any port on localhost.
         self.server = EchoHTTPServer(LOCALHOST, 0, task_dispatcher=td,
                                      adj=my_adj)
         self.port = self.server.socket.getsockname()[1]
@@ -99,7 +106,7 @@
                 # Clean!
                 break
             if time() >= timeout:
-                self.fail('Not all sockets were closed: %s' % `socket_map`)
+                self.fail('Leaked a socket: %s' % `socket_map`)
             poll(0.1, socket_map)
 
     def loop(self):
@@ -178,7 +185,7 @@
         s = 'This string has 32 characters.\r\n' * 32  # 1024 characters.
         self.testEchoResponse(h, body=(s * 1024))  # 1 MB
         self.testEchoResponse(h, {'Connection': 'close'},
-                            body=(s * 100))  # 100 KB
+                              body=(s * 100))  # 100 KB
 
     def testManyClients(self):
         conns = []