Commit 0d996b48 authored by Jérome Perrin's avatar Jérome Perrin

ZEO tests: wait for other nodes to register

When other nodes takes time to start they are not always registered
when the "main" node asserts that they are there.
We observed problems in an environment where resolving localhost (by
DNS) takes 10 seconds.

Also introduce getOtherZopeNodeList utility method that can be useful in
other ZEO tests in ProcessingNodeTestCase
parent e50bcc8b
......@@ -87,20 +87,12 @@ class TestERP5(ERP5TypeTestCase):
return "Conflict Resolution: ERP5"
def afterSetUp(self):
other_node = self.getOtherZopeNode()
other_node = self.getOtherZopeNodeList()[0]
self.other_node = self.portal.portal_web_services.connect(
"http://%s%s" % (other_node, self.portal.getPath()),
'ERP5TypeTestCase', '', 'xml-rpc')
self.login()
def getOtherZopeNode(self):
from Products.CMFActivity.ActivityTool import getCurrentNode
activity_tool = self.portal.portal_activities
node_list = list(activity_tool.getProcessingNodeList())
node_list.remove(getCurrentNode())
assert node_list, "this unit test must be run with at least 2 Zope nodes"
return node_list[0]
def testZODBCookie(self):
cookie_name = self._testMethodName
portal = self.portal
......
......@@ -93,14 +93,13 @@ class TestInvalidationBug(ERP5TypeTestCase):
def testLateInvalidationFromZEO(self):
### Check unit test is run properly
from ZEO.ClientStorage import ClientStorage
from Products.CMFActivity.ActivityTool import getCurrentNode
storage = self.portal._p_jar._storage
self.assertIsInstance(
storage,
ClientStorage,
"This test must be run with ZEO storage")
node_list = self.getOtherZopeNodeList()
activity_tool = self.portal.portal_activities
node_list = list(activity_tool.getProcessingNodeList())
node_list.remove(getCurrentNode())
assert node_list and isinstance(storage, ClientStorage), (
node_list, storage,
"this unit test must be run with at least 2 ZEO clients")
### Prepare unit test, to minimize amount of work during critical section
## make sure activity tool's OOBTree for family mapping is loaded before the test
......
......@@ -314,6 +314,23 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
ZopeTestCase._print(' done (%.3fs)\n' % (time.time() - start))
self.abort()
def getOtherZopeNodeList(self, node_count=2):
"""Wait for at least `node_count` (including the current node) to be
registered on portal activities and return the list of their node ids.
This aborts current transaction.
"""
for i in xrange(30):
node_list = list(self.portal.portal_activities.getProcessingNodeList())
if len(node_list) >= node_count:
node_list.remove(getCurrentNode())
return node_list
self.abort()
time.sleep(i * 0.1)
self.fail(
"No other activity node registered, make sure you are using"
" --activity_node=%s command line flag" % node_count)
def afterSetUp(self):
"""Initialize a node that will only process activities"""
self.startZServer()
......
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