Commit c19c2a05 authored by Jérome Perrin's avatar Jérome Perrin Committed by Kazuhiko Shiozaki

test: try to explicitly stop HTTP server at the end of tests

This prevents tracebacks during shutdown:

  Unhandled exception in thread started by <bound method Thread.__bootstrap of <Thread(Thread-1, stopped daemon 139820471113472)>>
  Traceback (most recent call last):
    File "soft/lib/python2.7/threading.py", line 774, in __bootstrap
      self.__bootstrap_inner()
    File "soft/lib/python2.7/threading.py", line 814, in __bootstrap_inner
      (self.name, _format_exc()))
    File "soft/lib/python2.7/traceback.py", line 242, in format_exc
      return ''.join(format_exception(etype, value, tb, limit))
    File "soft/lib/python2.7/traceback.py", line 141, in format_exception
      list = list + format_tb(tb, limit)
    File "soft/lib/python2.7/traceback.py", line 76, in format_tb
      return format_list(extract_tb(tb, limit))
    File "soft/lib/python2.7/traceback.py", line 100, in extract_tb
      linecache.checkcache(filename)
  TypeError: 'NoneType' object is not callable

Also rename the method because this is not longer *Z*server.

This waitress close() API is not public part of API, so we still ignore
the case where the server thread does not stop after 5 seconds. This
happens if some HTTP connections are still open at the end of test.
parent 9210e45b
...@@ -2603,7 +2603,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2603,7 +2603,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
self.assertEqual(activity_node, current_node) self.assertEqual(activity_node, current_node)
def test_getServerAddress(self): def test_getServerAddress(self):
host, port = self.startZServer() host, port = self.startHTTPServer()
ip = socket.gethostbyname(host) ip = socket.gethostbyname(host)
server_address = '%s:%s' % (ip, port) server_address = '%s:%s' % (ip, port)
address = getServerAddress() address = getServerAddress()
......
...@@ -428,7 +428,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase): ...@@ -428,7 +428,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
# non-recursive results clean of portal_tests/ or portal_tests/``run_only`` # non-recursive results clean of portal_tests/ or portal_tests/``run_only``
self.portal.portal_tests.TestTool_cleanUpTestResults(self.run_only or None) self.portal.portal_tests.TestTool_cleanUpTestResults(self.run_only or None)
self.tic() self.tic()
host, port = self.startZServer() host, port = self.startHTTPServer()
self.runner = FunctionalTestRunner(host, port, self) self.runner = FunctionalTestRunner(host, port, self)
def setSystemPreference(self): def setSystemPreference(self):
......
...@@ -1284,7 +1284,7 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin): ...@@ -1284,7 +1284,7 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
if len(setup_done) == 1: # make sure it is run only once if len(setup_done) == 1: # make sure it is run only once
self._setUpDummyMailHost() self._setUpDummyMailHost()
self.startZServer(verbose=True) self.startHTTPServer(verbose=True)
self._registerNode(distributing=1, processing=1) self._registerNode(distributing=1, processing=1)
self.loadPromise() self.loadPromise()
......
...@@ -151,9 +151,10 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -151,9 +151,10 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
pass pass
Lifetime.graceful_shutdown_loop() Lifetime.graceful_shutdown_loop()
def startZServer(self, verbose=False): @staticmethod
"""Start HTTP ZServer in background""" def startHTTPServer(verbose=False):
if self._server_address is None: """Start HTTP Server in background"""
if ProcessingNodeTestCase._server_address is None:
from Products.ERP5Type.tests.runUnitTest import log_directory from Products.ERP5Type.tests.runUnitTest import log_directory
log = os.path.join(log_directory, "Z2.log") log = os.path.join(log_directory, "Z2.log")
message = "Running %s server at %s:%s\n" message = "Running %s server at %s:%s\n"
...@@ -199,8 +200,11 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -199,8 +200,11 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
webdav_ports=webdav_ports), webdav_ports=webdav_ports),
logger, logger,
sockets=sockets) sockets=sockets)
ProcessingNodeTestCase._server = hs
ProcessingNodeTestCase._server_address = hs.addr ProcessingNodeTestCase._server_address = hs.addr
t = Thread(target=hs.run) ProcessingNodeTestCase._server_thread = t = Thread(
target=hs.run,
name='ProcessingNodeTestCase.startHTTPServer')
t.setDaemon(1) t.setDaemon(1)
t.start() t.start()
from Products.CMFActivity import ActivityTool from Products.CMFActivity import ActivityTool
...@@ -210,7 +214,15 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -210,7 +214,15 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
if ActivityTool.currentNode == ActivityTool._server_address: if ActivityTool.currentNode == ActivityTool._server_address:
ActivityTool.currentNode = None ActivityTool.currentNode = None
ActivityTool._server_address = None ActivityTool._server_address = None
return self._server_address return ProcessingNodeTestCase._server_address
startZServer = startHTTPServer # BBB
@staticmethod
def stopHTTPServer():
if ProcessingNodeTestCase._server_address is not None:
ProcessingNodeTestCase._server_address = None
ProcessingNodeTestCase._server.close()
ProcessingNodeTestCase._server_thread.join(5)
def _registerNode(self, distributing, processing): def _registerNode(self, distributing, processing):
"""Register node to process and/or distribute activities""" """Register node to process and/or distribute activities"""
...@@ -338,7 +350,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -338,7 +350,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
def afterSetUp(self): def afterSetUp(self):
"""Initialize a node that will only process activities""" """Initialize a node that will only process activities"""
self.startZServer() self.startHTTPServer()
# Make sure to still have possibilities to edit components # Make sure to still have possibilities to edit components
addUserToDeveloperRole('ERP5TypeTestCase') addUserToDeveloperRole('ERP5TypeTestCase')
from Zope2.custom_zodb import cluster from Zope2.custom_zodb import cluster
......
...@@ -693,6 +693,7 @@ def runUnitTestList(test_list, verbosity=1, debug=0, run_only=None): ...@@ -693,6 +693,7 @@ def runUnitTestList(test_list, verbosity=1, debug=0, run_only=None):
raise raise
finally: finally:
ProcessingNodeTestCase.unregisterNode() ProcessingNodeTestCase.unregisterNode()
ProcessingNodeTestCase.stopHTTPServer()
db_factory.close() db_factory.close()
Storage.close() Storage.close()
if node_pid_list is not None: if node_pid_list is not None:
......
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