Commit e03200f8 authored by Grégory Wisniewski's avatar Grégory Wisniewski

(Re-)move getNewUUID() at module level since it's required by functionals test

case. Fix dirty work on getTwoIDs() and replace while loops by a simple check
and two ordered UUIDs are needed.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1180 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 9071da4e
...@@ -49,6 +49,13 @@ DB_ADMIN = 'root' ...@@ -49,6 +49,13 @@ DB_ADMIN = 'root'
DB_PASSWD = None DB_PASSWD = None
DB_USER = 'test' DB_USER = 'test'
def getNewUUID():
""" Return a valid UUID """
uuid = protocol.INVALID_UUID
while uuid == protocol.INVALID_UUID:
uuid = os.urandom(16)
return uuid
class NeoTestBase(unittest.TestCase): class NeoTestBase(unittest.TestCase):
""" Base class for neo tests, implements common checks """ """ Base class for neo tests, implements common checks """
...@@ -108,19 +115,14 @@ class NeoTestBase(unittest.TestCase): ...@@ -108,19 +115,14 @@ class NeoTestBase(unittest.TestCase):
# XXX: according to changes with namespaced UUIDs, it would be better to # XXX: according to changes with namespaced UUIDs, it would be better to
# implement get<NodeType>UUID() methods # implement get<NodeType>UUID() methods
def getNewUUID(self): def getNewUUID(self):
""" Return a valid UUID """ self.uuid = getNewUUID()
uuid = protocol.INVALID_UUID return self.uuid
while uuid == protocol.INVALID_UUID:
uuid = os.urandom(16)
self.uuid = uuid
return uuid
def getTwoIDs(self): def getTwoIDs(self):
""" Return a tuple of two sorted UUIDs """ """ Return a tuple of two sorted UUIDs """
# generate two ptid, first is lower # generate two ptid, first is lower
ptids = self.getNewUUID(), self.getNewUUID() uuids = self.getNewUUID(), self.getNewUUID()
return min(ptids), max(ptids) return min(uuids), max(uuids)
ptid = min(ptids)
def getFakeConnection(self, uuid=None, address=('127.0.0.1', 10000)): def getFakeConnection(self, uuid=None, address=('127.0.0.1', 10000)):
return Mock({ return Mock({
......
...@@ -337,8 +337,8 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -337,8 +337,8 @@ class MasterServerElectionTests(NeoTestBase):
def test_09_handleAnswerPrimaryMaster1(self): def test_09_handleAnswerPrimaryMaster1(self):
# test with master node and greater uuid # test with master node and greater uuid
uuid = self.getNewUUID() uuid = self.getNewUUID()
while uuid < self.app.uuid: if uuid < self.app.uuid:
uuid = self.getNewUUID() self.app.uuid, uuid = self.app.uuid, uuid
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
conn.setUUID(uuid) conn.setUUID(uuid)
...@@ -358,8 +358,8 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -358,8 +358,8 @@ class MasterServerElectionTests(NeoTestBase):
def test_09_handleAnswerPrimaryMaster2(self): def test_09_handleAnswerPrimaryMaster2(self):
# test with master node and lesser uuid # test with master node and lesser uuid
uuid = self.getNewUUID() uuid = self.getNewUUID()
while uuid > self.app.uuid: if uuid > self.app.uuid:
uuid = self.getNewUUID() self.app.uuid, uuid = self.app.uuid, uuid
conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port), conn = ClientConnection(self.app.em, self.election, addr = ("127.0.0.1", self.master_port),
connector_handler = DoNothingConnector) connector_handler = DoNothingConnector)
conn.setUUID(uuid) conn.setUUID(uuid)
......
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