[Checkins] SVN: zc.monitor/trunk/src/zc/monitor/ added test for start()... only caveat is I cannot get rid of the async thread

Adam Groszer agroszer at gmail.com
Sun Jan 24 09:20:01 EST 2010


Log message for revision 108436:
  added test for start()... only caveat is I cannot get rid of the async thread
  

Changed:
  U   zc.monitor/trunk/src/zc/monitor/README.txt
  U   zc.monitor/trunk/src/zc/monitor/__init__.py

-=-
Modified: zc.monitor/trunk/src/zc/monitor/README.txt
===================================================================
--- zc.monitor/trunk/src/zc/monitor/README.txt	2010-01-24 13:24:08 UTC (rev 108435)
+++ zc.monitor/trunk/src/zc/monitor/README.txt	2010-01-24 14:20:01 UTC (rev 108436)
@@ -208,3 +208,62 @@
 
     >>> connection.test_input('quit\n')
     -> CLOSE
+
+Start server
+------------
+
+    >>> import time
+    >>> import zope.testing.loggingsupport, logging
+    >>> loghandler = zope.testing.loggingsupport.InstalledHandler(
+    ...                  None, level=logging.INFO)
+
+
+    >>> zc.monitor.start(9644)
+    True
+
+    >>> print loghandler
+    zc.ngi.async.server INFO
+      listening on ('', 9644)
+
+    >>> zc.monitor.last_listener.close()
+    >>> zc.monitor.last_listener = None
+    >>> time.sleep(0.1)
+
+
+
+    >>> loghandler.clear()
+
+    >>> zc.monitor.start(('127.0.0.1', 9644))
+    True
+
+    >>> print loghandler
+    zc.ngi.async.server INFO
+      listening on ('127.0.0.1', 9644)
+
+    >>> zc.monitor.last_listener.close()
+    >>> zc.monitor.last_listener = None
+    >>> time.sleep(0.1)
+
+Trying to rebind to a port in use:
+
+    >>> loghandler.clear()
+
+    >>> zc.monitor.start(('127.0.0.1', 9644))
+    True
+
+    >>> zc.monitor.start(('127.0.0.1', 9644))
+    False
+
+    >>> print loghandler
+    zc.ngi.async.server INFO
+      listening on ('127.0.0.1', 9644)
+    zc.ngi.async.server WARNING
+      unable to listen on ('127.0.0.1', 9644)
+    root WARNING
+      unable to start zc.monitor server because the address ('127.0.0.1', 9644) is in use.
+
+    >>> zc.monitor.last_listener.close()
+    >>> zc.monitor.last_listener = None
+    >>> time.sleep(0.1)
+
+    >>> loghandler.uninstall()
\ No newline at end of file

Modified: zc.monitor/trunk/src/zc/monitor/__init__.py
===================================================================
--- zc.monitor/trunk/src/zc/monitor/__init__.py	2010-01-24 13:24:08 UTC (rev 108435)
+++ zc.monitor/trunk/src/zc/monitor/__init__.py	2010-01-24 14:20:01 UTC (rev 108436)
@@ -69,6 +69,8 @@
     def handle_close(self, connection, reason):
         pass                            # Don't care
 
+#testing support
+last_listener = None
 
 def start(address):
     """start monitor server.
@@ -90,14 +92,16 @@
         ourAddress = address
 
     try:
-        zc.ngi.async.listener(ourAddress, Server)
+        global last_listener
+        last_listener = zc.ngi.async.listener(ourAddress, Server)
     except socket.error, e:
         if e.args[0] == errno.EADDRINUSE:
             # Don't kill the process just because somebody else has our port.
             # This might be a zopectl debug or some other innocuous problem.
             logging.warning(
-                'unable to start zc.monitor server because port %d is in use.',
-                port)
+                'unable to start zc.monitor server because the address %s '\
+                'is in use.',
+                ourAddress)
             return False
         else:
             raise



More information about the checkins mailing list