thisdir = os.path.join(os.getcwd(), os.path.dirname(__file__))
target_line = open(p.error_log, 'rb').readlines()[-10]
if not ntob("I am an old SIGTERM handler.") in target_line:
self.fail("Old SIGTERM handler did not run.\n%r" % target_line)
+ def test_wait_for_occupied_port_INADDR_ANY(self):
+ Wait on INADDR_ANY should not raise IOError
+ In cases where the loopback interface does not exist, CherryPy cannot
+ effectively determine if a port binding to INADDR_ANY was effected.
+ In this situation, CherryPy should assume that it failed to detect
+ the binding (not that the binding failed) and only warn that it could
+ # At such a time that CherryPy can reliably determine one or more
+ # viable IP addresses of the host, this test may be removed.
+ # Simulate the behavior we observe when no loopback interface is
+ # present by: finding a port that's not occupied, then wait on it.
+ free_port = self.find_free_port()
+ servers = cherrypy.process.servers
+ def with_shorter_timeouts(func):
+ A context where occupied_port_timeout is much smaller to speed
+ # When we have Python 2.5, simplify using the with_statement.
+ orig_timeout = servers.occupied_port_timeout
+ servers.occupied_port_timeout = .07
+ servers.occupied_port_timeout = orig_timeout
+ # Wait on the free port that's unbound
+ servers.wait_for_occupied_port('0.0.0.0', free_port)
+ # The wait should still raise an IO error if INADDR_ANY was
+ self.assertRaises(IOError, servers.wait_for_occupied_port,
+ '127.0.0.1', free_port)
+ def find_free_port(self):
+ "Find a free port by binding to port 0 then unbinding."
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ free_port = sock.getsockname()