Commit 1d5b4e64 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Apply monkey patch in setUp and restore previous methods in tearDown to not

modify environment for next tests.
Remove used class skeleton for client application tests.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@605 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent c786a9e8
......@@ -35,54 +35,27 @@ def _getMasterConnection(self):
self.num_replicas = 1
self.pt = PartitionTable(self.num_partitions, self.num_replicas)
return Mock() # master_conn
Application._getMasterConnection_ord = Application._getMasterConnection
Application._getMasterConnection = _getMasterConnection
def _waitMessage(self, conn=None, msg_id=None, handler=None):
if conn is not None and handler is not None:
handler.dispatch(conn, conn.fakeReceived())
else:
raise NotImplementedError
Application._waitMessage_org = Application._waitMessage
Application._waitMessage = _waitMessage
class TestSocketConnector(object):
"""
Test socket connector.
Exports both an API compatible with neo.connector.SocketConnector
and a test-only API which allows sending packets to created connectors.
"""
def __init__(self):
raise NotImplementedError
def makeClientConnection(self, addr):
raise NotImplementedError
def makeListeningConnection(self, addr):
raise NotImplementedError
def getError(self):
raise NotImplementedError
def getDescriptor(self):
raise NotImplementedError
def getNewConnection(self):
raise NotImplementedError
def shutdown(self):
raise NotImplementedError
def receive(self):
raise NotImplementedError
def send(self, msg):
raise NotImplementedError
class ClientApplicationTest(NeoTestBase):
def setUp(self):
logging.basicConfig(level = logging.WARNING)
# apply monkey patches
self._getMasterConnection = Application._getMasterConnection
self._waitMessage = Application._waitMessage
Application._getMasterConnection = _getMasterConnection
Application._waitMessage = _waitMessage
def tearDown(self):
# restore environnement
Application._getMasterConnection = self._getMasterConnection
Application._waitMessage = self._waitMessage
# some helpers
......@@ -220,7 +193,7 @@ class ClientApplicationTest(NeoTestBase):
app.pt = Mock({ 'getCellList': (cell, ), })
app.cp = Mock({ 'getConnForNode' : conn})
app.local_var.asked_object = -1
Application._waitMessage = Application._waitMessage_org
Application._waitMessage = self._waitMessage
self.assertRaises(NEOStorageNotFoundError, app.load, oid)
self.checkAskObject(conn)
Application._waitMessage = _waitMessage
......@@ -830,7 +803,7 @@ class ClientApplicationTest(NeoTestBase):
app.pt = Mock({ 'operational': ReturnValues(False, False, True, True)})
self.all_passed = False
try:
app.connectToPrimaryMasterNode_org()
self.connectToPrimaryMasterNode(app)
finally:
Application._waitMessage = _waitMessage_old
self.assertEquals(len(app.pt.mockGetNamedCalls('clear')), 1)
......
......@@ -237,6 +237,9 @@ class ZODBTests(unittest.TestCase):
NEOProcess(NEO_STORAGE, '-vRc', config_file_path, '-s', 'storage2', '-l', s2_log)
NEOProcess(NEO_STORAGE, '-vRc', config_file_path, '-s', 'storage3', '-l', s3_log)
NEOProcess(NEO_STORAGE, '-vRc', config_file_path, '-s', 'storage4', '-l', s4_log)
# wait a bit during cluster startup, this is just to avoid many
# 'connection refused' messages in logs
time.sleep(5)
# Send Storage output to a logfile
self._storage = Storage(
master_nodes=NEO_MASTER_NODES,
......
......@@ -61,8 +61,6 @@ def expectMessage(self, packet):
if self.connector is not None:
self.connector.expectMessage(packet)
ClientConnection._addPacket = _addPacket
ClientConnection.expectMessage = expectMessage
class MasterElectionTests(NeoTestBase):
......@@ -125,15 +123,22 @@ server: 127.0.0.1:10023
for node in self.app.nm.getMasterNodeList():
self.app.unconnected_master_node_set.add(node.getServer())
node.setState(RUNNING_STATE)
# define some variable to simulate client and storage node
self.client_port = 11022
self.storage_port = 10021
self.master_port = 10011
# apply monkey patches
self._addPacket = ClientConnection._addPacket
self.expectMessage = ClientConnection.expectMessage
ClientConnection._addPacket = _addPacket
ClientConnection.expectMessage = expectMessage
def tearDown(self):
# Delete tmp file
os.remove(self.tmp_path)
# restore environnement
ClientConnection._addPacket = self._addPacket
ClientConnection.expectMessage = self.expectMessage
# Common methods
def getNewUUID(self):
......
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