Commit 6984c60a authored by Grégory Wisniewski's avatar Grégory Wisniewski

Fix tests where _addPacket calls where check to zero time with calls to

checkNoPacketSent that do the good job.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@517 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 22f00fe1
......@@ -271,7 +271,7 @@ class ClientApplicationTest(unittest.TestCase):
app.cp = Mock({ 'getConnForNode' : conn})
result = app.load(oid)
self.assertEquals(result, ('', tid1))
self.assertEquals(len(conn.mockGetNamedCalls('_addPacket')), 0)
self.checkNoPacketSent(conn)
def test_loadSerial(self):
app = self.getApp()
......
......@@ -88,6 +88,11 @@ server: 127.0.0.1:10023
self.uuid = uuid
return uuid
def checkNoPacketSent(self, conn):
self.assertEquals(len(conn.mockGetNamedCalls('notify')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('answer')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('ask')), 0)
def test_01_getNextPartitionTableID(self):
# must raise as we don"t have one
self.assertEqual(self.app.lptid, INVALID_PTID)
......@@ -160,7 +165,7 @@ server: 127.0.0.1:10023
c_node = ClientNode(uuid = self.getNewUUID())
self.app.broadcastNodeInformation(c_node)
# check conn
self.assertEquals(len(client_conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(client_conn)
self.assertEquals(len(master_conn.mockGetNamedCalls("notify")), 1)
call = master_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0)
......@@ -180,7 +185,7 @@ server: 127.0.0.1:10023
s_node = ClientNode(uuid = self.getNewUUID(), server=("127.1.0.1", 3361))
self.app.broadcastNodeInformation(c_node)
# check conn
self.assertEquals(len(client_conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(client_conn)
self.assertEquals(len(master_conn.mockGetNamedCalls("notify")), 1)
call = master_conn.mockGetNamedCalls("notify")[0]
packet = call.getParam(0)
......
......@@ -496,7 +496,7 @@ server: 127.0.0.1:10020
num_replicas=self.app.num_replicas,
**args)
self.assertEquals(len(conn.mockGetNamedCalls("setUUID")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
# create a new partition table
self.bootstrap.handleAcceptNodeIdentification(
......@@ -595,7 +595,7 @@ server: 127.0.0.1:10020
self.assertEquals(n.getUUID(), new_master[2])
self.assertEquals(len(conn.mockGetNamedCalls('setHandler')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('close')), 0)
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
def test_10_handleAnswerPrimaryMaster03(self):
# invalid primary master uuid -> close connection
......@@ -615,7 +615,7 @@ server: 127.0.0.1:10020
self.assertEquals(self.app.trying_master_node, None)
self.assertEquals(len(conn.mockGetNamedCalls('setHandler')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('close')), 1)
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
def test_10_handleAnswerPrimaryMaster04(self):
# trying_master_node is not pmn -> close connection
......@@ -637,7 +637,7 @@ server: 127.0.0.1:10020
self.assertEquals(len(conn.mockGetNamedCalls('setHandler')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('close')), 1)
self.assertEquals(self.app.trying_master_node, None)
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
def test_10_handleAnswerPrimaryMaster05(self):
# trying_master_node is pmn -> set verification handler
......@@ -661,7 +661,7 @@ server: 127.0.0.1:10020
self.assertTrue(isinstance(call.getParam(0), VerificationEventHandler))
self.assertEquals(len(conn.mockGetNamedCalls('close')), 0)
self.assertEquals(self.app.trying_master_node, pmn)
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
def test_10_handleAnswerPrimaryMaster06(self):
# primary_uuid not known -> nothing happen
......@@ -681,7 +681,7 @@ server: 127.0.0.1:10020
self.assertEquals(self.app.trying_master_node, None)
self.assertEquals(len(conn.mockGetNamedCalls('setHandler')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('close')), 0)
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
if __name__ == "__main__":
unittest.main()
......
......@@ -752,7 +752,7 @@ server: 127.0.0.1:10020
serial=INVALID_SERIAL,
tid=INVALID_TID)
self.assertEquals(len(self.app.event_queue), 1)
self.assertEquals(len(conn.mockGetNamedCalls('_addPacket')), 0)
self.checkNoPacketSent(conn)
self.assertEquals(len(self.app.dm.mockGetNamedCalls('getObject')), 0)
def test_24_handleAskObject2(self):
......@@ -918,7 +918,7 @@ server: 127.0.0.1:10020
self.assertEquals(len(self.app.event_queue), 1)
t_after = self.app.transaction_dict.items()[:]
self.assertEquals(t_before, t_after)
self.assertEquals(len(conn.mockGetNamedCalls('_addPacket')), 0)
self.checkNoPacketSent(conn)
self.assertTrue(oid in self.app.store_lock_dict)
def test_28_handleAskStoreObject3(self):
......
......@@ -147,6 +147,12 @@ server: 127.0.0.1:10020
""" Check if the NotReadyError exception wxas raised """
self.assertRaises(protocol.NotReadyError, method, *args, **kwargs)
def checkNoPacketSent(self, conn):
# no packet should be sent
self.assertEquals(len(conn.mockGetNamedCalls('notify')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('answer')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('ask')), 0)
# Tests
def test_01_connectionAccepted(self):
uuid = self.getNewUUID()
......@@ -154,7 +160,7 @@ server: 127.0.0.1:10020
"getAddress" : ("127.0.0.1", self.client_port)})
self.verification.connectionAccepted(conn, None, ("127.0.0.1", self.client_port))
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
def test_02_timeoutExpired(self):
# listening connection
......@@ -164,7 +170,7 @@ server: 127.0.0.1:10020
"isServerConnection" : True})
self.verification.timeoutExpired(conn)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
# client connection
uuid = self.getNewUUID()
......@@ -173,7 +179,7 @@ server: 127.0.0.1:10020
"isServerConnection" : False})
self.assertRaises(PrimaryFailure, self.verification.timeoutExpired, conn,)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
def test_03_connectionClosed(self):
# listening connection
......@@ -183,7 +189,7 @@ server: 127.0.0.1:10020
"isServerConnection" : True})
self.verification.connectionClosed(conn)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
# client connection
uuid = self.getNewUUID()
......@@ -192,7 +198,7 @@ server: 127.0.0.1:10020
"isServerConnection" : False})
self.assertRaises(PrimaryFailure, self.verification.connectionClosed, conn,)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
def test_04_peerBroken(self):
......@@ -203,7 +209,7 @@ server: 127.0.0.1:10020
"isServerConnection" : True})
self.verification.peerBroken(conn)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
# client connection
uuid = self.getNewUUID()
......@@ -212,7 +218,7 @@ server: 127.0.0.1:10020
"isServerConnection" : False})
self.assertRaises(PrimaryFailure, self.verification.peerBroken, conn,)
# nothing happens
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
def test_05_handleRequestNodeIdentification(self):
......
......@@ -29,6 +29,11 @@ class testEvent(unittest.TestCase):
def tearDown(self):
pass
def checkNoPacketSent(self, conn):
self.assertEquals(len(conn.mockGetNamedCalls('notify')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('answer')), 0)
self.assertEquals(len(conn.mockGetNamedCalls('ask')), 0)
def test_01_EpollEventManager(self):
# init one
em = EpollEventManager()
......@@ -148,7 +153,7 @@ class testEvent(unittest.TestCase):
self.assertEquals(len(conn.mockGetNamedCalls("close")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("unlock")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# call with time < t < critical_time
......@@ -204,7 +209,7 @@ class testEvent(unittest.TestCase):
self.assertEquals(len(conn.mockGetNamedCalls("close")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("unlock")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# call with time < t < critical_time
......@@ -217,7 +222,7 @@ class testEvent(unittest.TestCase):
self.assertEquals(len(conn.mockGetNamedCalls("close")), 0)
self.assertEquals(len(conn.mockGetNamedCalls("unlock")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 0)
# call with time < critical_time < t
......@@ -230,7 +235,7 @@ class testEvent(unittest.TestCase):
self.assertEquals(len(conn.mockGetNamedCalls("close")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("unlock")), 2)
self.assertEquals(len(conn.mockGetNamedCalls("expectMessage")), 1)
self.assertEquals(len(conn.mockGetNamedCalls("_addPacket")), 0)
self.checkNoPacketSent(conn)
self.assertEquals(len(handler.mockGetNamedCalls("timeoutExpired")), 1)
......
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