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

Use more getFakeConnection() to build a clean mock object.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2055 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 7b66b2c2
......@@ -149,10 +149,14 @@ class NeoTestBase(unittest.TestCase):
uuids = self.getNewUUID(), self.getNewUUID()
return min(uuids), max(uuids)
def getFakeConnection(self, uuid=None, address=('127.0.0.1', 10000)):
def getFakeConnection(self, uuid=None, address=('127.0.0.1', 10000),
is_server=False):
return Mock({
'getUUID': uuid,
'getAddress': address,
'isServer': is_server,
'__repr__': 'FakeConnection',
'__nonzero__': 0,
})
def checkProtocolErrorRaised(self, method, *args, **kwargs):
......
......@@ -62,11 +62,8 @@ class MasterClientElectionTests(NeoTestBase):
def identifyToMasterNode(self):
node = self.app.nm.getMasterList()[0]
node.setUUID(self.getNewUUID())
conn = Mock({
"getUUID": node.getUUID(),
"getAddress": node.getAddress(),
"getConnector": Mock(),
})
conn = self.getFakeConnection(uuid=node.getUUID(),
address=node.getAddress())
return (node, conn)
def _checkUnconnected(self, node):
......
......@@ -49,43 +49,31 @@ class StorageInitializationHandlerTests(NeoTestBase):
def getLastUUID(self):
return self.uuid
def getClientConnection(self):
address = ("127.0.0.1", self.client_port)
return self.getFakeConnection(uuid=self.getNewUUID(), address=address)
def test_02_timeoutExpired(self):
# client connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServer" : False})
conn = self.getClientConnection()
self.assertRaises(PrimaryFailure, self.verification.timeoutExpired, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_03_connectionClosed(self):
# client connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServer" : False})
conn = self.getClientConnection()
self.assertRaises(PrimaryFailure, self.verification.connectionClosed, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_04_peerBroken(self):
# client connection
uuid = self.getNewUUID()
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServer" : False})
conn = self.getClientConnection()
self.assertRaises(PrimaryFailure, self.verification.peerBroken, conn,)
# nothing happens
self.checkNoPacketSent(conn)
def test_09_sendPartitionTable(self):
uuid = self.getNewUUID()
# send a table
conn = Mock({"getUUID" : uuid,
"getAddress" : ("127.0.0.1", self.client_port),
"isServer" : False})
conn = self.getClientConnection()
self.app.pt = PartitionTable(3, 2)
node_1 = self.getNewUUID()
node_2 = self.getNewUUID()
......
......@@ -29,10 +29,7 @@ from neo.protocol import INVALID_TID, INVALID_OID
class StorageMasterHandlerTests(NeoTestBase):
def checkHandleUnexpectedPacket(self, _call, _msg_type, _listening=True, **kwargs):
conn = Mock({
"getAddress" : ("127.0.0.1", self.master_port),
"isServer": _listening,
})
conn = self.getMasterConnection(is_server=_listening)
# hook
self.operation.peerBroken = lambda c: c.peerBrokendCalled()
self.checkUnexpectedPacketRaised(_call, conn=conn, **kwargs)
......@@ -58,41 +55,32 @@ class StorageMasterHandlerTests(NeoTestBase):
def tearDown(self):
NeoTestBase.tearDown(self)
def getMasterConnection(self):
address = ("127.0.0.1", self.master_port)
return self.getFakeConnection(uuid=self.master_uuid, address=address)
def test_06_timeoutExpired(self):
# client connection
conn = Mock({
"getUUID": self.master_uuid,
"getAddress" : ("127.0.0.1", self.master_port),
})
conn = self.getMasterConnection()
self.assertRaises(PrimaryFailure, self.operation.timeoutExpired, conn)
self.checkNoPacketSent(conn)
def test_07_connectionClosed2(self):
# primary has closed the connection
conn = Mock({
"getUUID": self.master_uuid,
"getAddress" : ("127.0.0.1", self.master_port),
})
conn = self.getMasterConnection()
self.assertRaises(PrimaryFailure, self.operation.connectionClosed, conn)
self.checkNoPacketSent(conn)
def test_08_peerBroken(self):
# client connection
conn = Mock({
"getUUID": self.master_uuid,
"getAddress" : ("127.0.0.1", self.master_port),
})
conn = self.getMasterConnection()
self.assertRaises(PrimaryFailure, self.operation.peerBroken, conn)
self.checkNoPacketSent(conn)
def test_14_notifyPartitionChanges1(self):
# old partition change -> do nothing
app = self.app
conn = Mock({
"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
conn = self.getMasterConnection()
app.replicator = Mock({})
self.app.pt = Mock({'getID': 1})
count = len(self.app.nm.getList())
......@@ -113,10 +101,7 @@ class StorageMasterHandlerTests(NeoTestBase):
(2, uuid3, CellStates.OUT_OF_DATE),
)
# context
conn = Mock({
"isServer": False,
"getAddress" : ("127.0.0.1", self.master_port),
})
conn = self.getMasterConnection()
app = self.app
# register nodes
app.nm.createStorage(uuid=uuid1)
......
......@@ -45,7 +45,7 @@ class HandlerTests(NeoTestBase):
self.assertEquals(len(calls), 1)
def test_dispatch(self):
conn = Mock({'getAddress': ('127.0.0.1', 10000)})
conn = self.getFakeConnection()
packet = self.getFakePacket()
# all is ok
self.setFakeMethod(lambda c: None)
......
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