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