Commit 9bfd213a authored by Grégory Wisniewski's avatar Grégory Wisniewski

Factorise test code.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1431 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent fed72d56
......@@ -301,14 +301,13 @@ class MasterStorageHandlerTests(NeoTestBase):
else:
self.assertEquals(state, CellStates.DISCARDED)
def test_15_peerBroken(self):
def _testWithMethod(self, method, state):
service = self.service
uuid = self.identifyToMasterNode()
# do nothing if no uuid
conn = self.getFakeConnection(None, self.storage_address)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
service.peerBroken(conn)
method(conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
# add a second storage node and then declare it as broken
self.identifyToMasterNode(port = self.storage_port+2)
......@@ -321,16 +320,15 @@ class MasterStorageHandlerTests(NeoTestBase):
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING)
service.peerBroken(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.BROKEN)
method(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), state)
self.failUnless(lptid < self.app.pt.getID())
# give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.peerBroken, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN)
self.assertRaises(OperationFailure, method, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), state)
self.failUnless(lptid < self.app.pt.getID())
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
......@@ -344,111 +342,23 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.peerBroken(conn)
method(conn)
# node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
def test_15_peerBroken(self):
self._testWithMethod(self.service.peerBroken, NodeStates.BROKEN)
def test_16_timeoutExpired(self):
service = self.service
uuid = self.identifyToMasterNode()
# do nothing if no uuid
conn = self.getFakeConnection(None, self.storage_address)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
# add a second storage node and then declare it as temp down
self.identifyToMasterNode(port = self.storage_port+2)
storage_uuid = self.identifyToMasterNode(port = self.storage_port+1)
# filled the pt
self.app.pt.make(self.app.nm.getStorageList())
self.assertTrue(self.app.pt.filled())
self.assertTrue(self.app.pt.operational())
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING)
service.timeoutExpired(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
self._testWithMethod(self.service.timeoutExpired,
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.timeoutExpired, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID()
packet = AskBeginTransaction()
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.timeoutExpired(conn)
# node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
def test_17_connectionClosed(self):
service = self.service
uuid = self.identifyToMasterNode()
# do nothing if no uuid
conn = self.getFakeConnection(None, self.storage_address)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
service.connectionClosed(conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
# add a second storage node and then declare it as temp down
self.identifyToMasterNode(port = self.storage_port+2)
storage_uuid = self.identifyToMasterNode(port = self.storage_port+1)
# filled the pt
self.app.pt.make(self.app.nm.getStorageList())
self.assertTrue(self.app.pt.filled())
self.assertTrue(self.app.pt.operational())
conn = self.getFakeConnection(storage_uuid, ('127.0.0.1', self.storage_port+1))
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING)
service.connectionClosed(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
self._testWithMethod(self.service.connectionClosed,
NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.connectionClosed, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.TEMPORARILY_DOWN)
self.assertEquals(lptid, self.app.pt.getID())
# give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
port = self.client_port)
conn = self.getFakeConnection(client_uuid, self.client_address)
lptid = self.app.pt.getID()
packet = AskBeginTransaction()
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
service.askBeginTransaction(conn, packet)
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3)
service.connectionClosed(conn)
# node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0)
if __name__ == '__main__':
......
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