Commit 4d1168e1 authored by Jérome Perrin's avatar Jérome Perrin

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