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): ...@@ -301,14 +301,13 @@ class MasterStorageHandlerTests(NeoTestBase):
else: else:
self.assertEquals(state, CellStates.DISCARDED) self.assertEquals(state, CellStates.DISCARDED)
def _testWithMethod(self, method, state):
def test_15_peerBroken(self):
service = self.service service = self.service
uuid = self.identifyToMasterNode() uuid = self.identifyToMasterNode()
# do nothing if no uuid # do nothing if no uuid
conn = self.getFakeConnection(None, self.storage_address) conn = self.getFakeConnection(None, self.storage_address)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING) 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) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
# add a second storage node and then declare it as broken # add a second storage node and then declare it as broken
self.identifyToMasterNode(port = self.storage_port+2) self.identifyToMasterNode(port = self.storage_port+2)
...@@ -321,16 +320,15 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -321,16 +320,15 @@ class MasterStorageHandlerTests(NeoTestBase):
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
service.peerBroken(conn) method(conn)
self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(storage_uuid).getState(), state)
NodeStates.BROKEN)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give an uuid, must raise as no other storage node available # give an uuid, must raise as no other storage node available
conn = self.getFakeConnection(uuid, self.storage_address) conn = self.getFakeConnection(uuid, self.storage_address)
lptid = self.app.pt.getID() lptid = self.app.pt.getID()
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.RUNNING)
self.assertRaises(OperationFailure, service.peerBroken, conn) self.assertRaises(OperationFailure, method, conn)
self.assertEquals(self.app.nm.getByUUID(uuid).getState(), NodeStates.BROKEN) self.assertEquals(self.app.nm.getByUUID(uuid).getState(), state)
self.failUnless(lptid < self.app.pt.getID()) self.failUnless(lptid < self.app.pt.getID())
# give a client uuid which have unfinished transactions # give a client uuid which have unfinished transactions
client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT, client_uuid = self.identifyToMasterNode(node_type=NodeTypes.CLIENT,
...@@ -344,111 +342,23 @@ class MasterStorageHandlerTests(NeoTestBase): ...@@ -344,111 +342,23 @@ class MasterStorageHandlerTests(NeoTestBase):
self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(), self.assertEquals(self.app.nm.getByUUID(client_uuid).getState(),
NodeStates.RUNNING) NodeStates.RUNNING)
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 3) 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 # node must be have been remove, and no more transaction must remains
self.assertEquals(self.app.nm.getByUUID(client_uuid), None) self.assertEquals(self.app.nm.getByUUID(client_uuid), None)
self.assertEquals(lptid, self.app.pt.getID()) self.assertEquals(lptid, self.app.pt.getID())
self.assertEquals(len(self.app.finishing_transaction_dict.keys()), 0) 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): def test_16_timeoutExpired(self):
service = self.service self._testWithMethod(self.service.timeoutExpired,
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(),
NodeStates.TEMPORARILY_DOWN) 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): def test_17_connectionClosed(self):
service = self.service self._testWithMethod(self.service.connectionClosed,
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(),
NodeStates.TEMPORARILY_DOWN) 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__': 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