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): ...@@ -35,54 +35,27 @@ def _getMasterConnection(self):
self.num_replicas = 1 self.num_replicas = 1
self.pt = PartitionTable(self.num_partitions, self.num_replicas) self.pt = PartitionTable(self.num_partitions, self.num_replicas)
return Mock() # master_conn return Mock() # master_conn
Application._getMasterConnection_ord = Application._getMasterConnection
Application._getMasterConnection = _getMasterConnection
def _waitMessage(self, conn=None, msg_id=None, handler=None): def _waitMessage(self, conn=None, msg_id=None, handler=None):
if conn is not None and handler is not None: if conn is not None and handler is not None:
handler.dispatch(conn, conn.fakeReceived()) handler.dispatch(conn, conn.fakeReceived())
else: else:
raise NotImplementedError 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): class ClientApplicationTest(NeoTestBase):
def setUp(self): 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 # some helpers
...@@ -220,7 +193,7 @@ class ClientApplicationTest(NeoTestBase): ...@@ -220,7 +193,7 @@ class ClientApplicationTest(NeoTestBase):
app.pt = Mock({ 'getCellList': (cell, ), }) app.pt = Mock({ 'getCellList': (cell, ), })
app.cp = Mock({ 'getConnForNode' : conn}) app.cp = Mock({ 'getConnForNode' : conn})
app.local_var.asked_object = -1 app.local_var.asked_object = -1
Application._waitMessage = Application._waitMessage_org Application._waitMessage = self._waitMessage
self.assertRaises(NEOStorageNotFoundError, app.load, oid) self.assertRaises(NEOStorageNotFoundError, app.load, oid)
self.checkAskObject(conn) self.checkAskObject(conn)
Application._waitMessage = _waitMessage Application._waitMessage = _waitMessage
...@@ -830,7 +803,7 @@ class ClientApplicationTest(NeoTestBase): ...@@ -830,7 +803,7 @@ class ClientApplicationTest(NeoTestBase):
app.pt = Mock({ 'operational': ReturnValues(False, False, True, True)}) app.pt = Mock({ 'operational': ReturnValues(False, False, True, True)})
self.all_passed = False self.all_passed = False
try: try:
app.connectToPrimaryMasterNode_org() self.connectToPrimaryMasterNode(app)
finally: finally:
Application._waitMessage = _waitMessage_old Application._waitMessage = _waitMessage_old
self.assertEquals(len(app.pt.mockGetNamedCalls('clear')), 1) self.assertEquals(len(app.pt.mockGetNamedCalls('clear')), 1)
......
...@@ -237,6 +237,9 @@ class ZODBTests(unittest.TestCase): ...@@ -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', 'storage2', '-l', s2_log)
NEOProcess(NEO_STORAGE, '-vRc', config_file_path, '-s', 'storage3', '-l', s3_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) 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 # Send Storage output to a logfile
self._storage = Storage( self._storage = Storage(
master_nodes=NEO_MASTER_NODES, master_nodes=NEO_MASTER_NODES,
......
...@@ -61,8 +61,6 @@ def expectMessage(self, packet): ...@@ -61,8 +61,6 @@ def expectMessage(self, packet):
if self.connector is not None: if self.connector is not None:
self.connector.expectMessage(packet) self.connector.expectMessage(packet)
ClientConnection._addPacket = _addPacket
ClientConnection.expectMessage = expectMessage
class MasterElectionTests(NeoTestBase): class MasterElectionTests(NeoTestBase):
...@@ -125,15 +123,22 @@ server: 127.0.0.1:10023 ...@@ -125,15 +123,22 @@ server: 127.0.0.1:10023
for node in self.app.nm.getMasterNodeList(): for node in self.app.nm.getMasterNodeList():
self.app.unconnected_master_node_set.add(node.getServer()) self.app.unconnected_master_node_set.add(node.getServer())
node.setState(RUNNING_STATE) node.setState(RUNNING_STATE)
# define some variable to simulate client and storage node # define some variable to simulate client and storage node
self.client_port = 11022 self.client_port = 11022
self.storage_port = 10021 self.storage_port = 10021
self.master_port = 10011 self.master_port = 10011
# apply monkey patches
self._addPacket = ClientConnection._addPacket
self.expectMessage = ClientConnection.expectMessage
ClientConnection._addPacket = _addPacket
ClientConnection.expectMessage = expectMessage
def tearDown(self): def tearDown(self):
# Delete tmp file # Delete tmp file
os.remove(self.tmp_path) os.remove(self.tmp_path)
# restore environnement
ClientConnection._addPacket = self._addPacket
ClientConnection.expectMessage = self.expectMessage
# Common methods # Common methods
def getNewUUID(self): 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