Commit 2bb9e897 authored by Stefan H. Holek's avatar Stefan H. Holek

Fix AttributeError: 'ZEOServer' object has no attribute 'server'.

parent ac9692f7
......@@ -6,6 +6,9 @@ Changelog
- Drop support for Python 2.6 and 3.2.
- Fix AttributeError: 'ZEOServer' object has no attribute 'server' when
StorageServer creation fails.
4.2.0b1 (2015-06-05)
--------------------
......
......@@ -150,6 +150,7 @@ class ZEOServer:
def __init__(self, options):
self.options = options
self.server = None
def main(self):
self.setup_default_logging()
......@@ -162,7 +163,7 @@ class ZEOServer:
self.create_server()
self.loop_forever()
finally:
self.server.close()
self.close_server()
self.clear_socket()
self.remove_pidfile()
......@@ -262,6 +263,10 @@ class ZEOServer:
else:
self.server.loop()
def close_server(self):
if self.server is not None:
self.server.close()
def handle_sigterm(self):
log("terminated by SIGTERM")
sys.exit(0)
......
......@@ -70,7 +70,76 @@ class AttributeErrorTests(unittest.TestCase):
self.assertRaises(RuntimeError, zeo.main)
class CloseServerTests(unittest.TestCase):
def testCallSequence(self):
# The close_server hook is called after loop_forever
# has returned
zeo = TestZEOServer()
zeo.main()
self.assertEqual(zeo.called, [
"setup_default_logging",
"check_socket",
"clear_socket",
"make_pidfile",
"open_storages",
"setup_signals",
"create_server",
"loop_forever",
"close_server", # New
"clear_socket",
"remove_pidfile",
])
# The default implementation closes the storage server
self.assertEqual(hasattr(zeo, "server"), True)
self.assertEqual(zeo.server.called, ["close"])
def testFailLoopForever(self):
# The close_server hook is called if loop_forever exits
# with an exception
zeo = TestZEOServer(fail_loop_forever=True)
self.assertRaises(RuntimeError, zeo.main)
self.assertEqual(zeo.called, [
"setup_default_logging",
"check_socket",
"clear_socket",
"make_pidfile",
"open_storages",
"setup_signals",
"create_server",
"loop_forever",
"close_server",
"clear_socket",
"remove_pidfile",
])
# The storage server has been closed
self.assertEqual(hasattr(zeo, "server"), True)
self.assertEqual(zeo.server.called, ["close"])
def testFailCreateServer(self):
# The close_server hook is called if create_server exits
# with an exception
zeo = TestZEOServer(fail_create_server=True)
self.assertRaises(RuntimeError, zeo.main)
self.assertEqual(zeo.called, [
"setup_default_logging",
"check_socket",
"clear_socket",
"make_pidfile",
"open_storages",
"setup_signals",
"create_server",
"close_server",
"clear_socket",
"remove_pidfile",
])
# The server attribute is present but None
self.assertEqual(hasattr(zeo, "server"), True)
self.assertEqual(zeo.server, None)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(AttributeErrorTests))
suite.addTest(unittest.makeSuite(CloseServerTests))
return suite
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment