Commit 5b71dae3 authored by Vincent Pelletier's avatar Vincent Pelletier

First batch of fixes for testClientHandler:

- add trying_master_node where needed
- decrease the expected number of getNodeByUUID calls by one, since the first lookup is rendered useless by splitting handlers.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@716 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent cb51be00
...@@ -69,9 +69,10 @@ class ClientHandlerTests(NeoTestBase): ...@@ -69,9 +69,10 @@ class ClientHandlerTests(NeoTestBase):
def _testInitialMasterWithMethod(self, method): def _testInitialMasterWithMethod(self, method):
class App: class App:
primary_master_node = None primary_master_node = None
trying_master_node = 1
app = App() app = App()
method(self.getDispatcher(), app, PrimaryBootstrapHandler) method(self.getDispatcher(), app, PrimaryBootstrapHandler)
self.assertEqual(app.primary_master_node, -1) self.assertEqual(app.primary_master_node, None)
def _testMasterWithMethod(self, method, handler_class): def _testMasterWithMethod(self, method, handler_class):
uuid = self.getNewUUID() uuid = self.getNewUUID()
...@@ -198,13 +199,10 @@ class ClientHandlerTests(NeoTestBase): ...@@ -198,13 +199,10 @@ class ClientHandlerTests(NeoTestBase):
def test_notReady(self): def test_notReady(self):
app = Mock({'setNodeNotReady': None}) app = Mock({'setNodeNotReady': None})
dispatcher = self.getDispatcher() dispatcher = self.getDispatcher()
client_handler = PrimaryBootstrapHandler(app, dispatcher)
conn = self.getConnection() conn = self.getConnection()
client_handler.handleNotReady(conn, None, None)
self.assertEquals(len(app.mockGetNamedCalls('setNodeNotReady')), 1)
client_handler = StorageBootstrapHandler(app, dispatcher) client_handler = StorageBootstrapHandler(app, dispatcher)
client_handler.handleNotReady(conn, None, None) client_handler.handleNotReady(conn, None, None)
self.assertEquals(len(app.mockGetNamedCalls('setNodeNotReady')), 2) self.assertEquals(len(app.mockGetNamedCalls('setNodeNotReady')), 1)
def test_clientAcceptNodeIdentification(self): def test_clientAcceptNodeIdentification(self):
class App: class App:
...@@ -289,6 +287,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -289,6 +287,7 @@ class ClientHandlerTests(NeoTestBase):
node = Mock({'getNodeType': node_type}) node = Mock({'getNodeType': node_type})
class App: class App:
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': None, 'add': None}) nm = Mock({'getNodeByUUID': node, 'getNodeByServer': None, 'add': None})
trying_master_node = None
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app, self.getDispatcher()) client_handler = PrimaryBootstrapHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
...@@ -300,17 +299,13 @@ class ClientHandlerTests(NeoTestBase): ...@@ -300,17 +299,13 @@ class ClientHandlerTests(NeoTestBase):
def test_unknownNodeAnswerPrimaryMaster(self): def test_unknownNodeAnswerPrimaryMaster(self):
node = Mock({'getNodeType': MASTER_NODE_TYPE}) node = Mock({'getNodeType': MASTER_NODE_TYPE})
class App: class App:
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': None, 'add': None}) nm = Mock({'getNodeByServer': None, 'add': None})
primary_master_node = None primary_master_node = None
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app, self.getDispatcher()) client_handler = PrimaryBootstrapHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
test_master_list = [('127.0.0.1', 10010, self.getNewUUID())] test_master_list = [('127.0.0.1', 10010, self.getNewUUID())]
client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list) client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list)
# Test sanity check
getNodeByUUID_call_list = app.nm.mockGetNamedCalls('getNodeByUUID')
self.assertEqual(len(getNodeByUUID_call_list), 1)
self.assertEqual(getNodeByUUID_call_list[0].getParam(0), conn.getUUID())
# Check that yet-unknown master node got added # Check that yet-unknown master node got added
getNodeByServer_call_list = app.nm.mockGetNamedCalls('getNodeByServer') getNodeByServer_call_list = app.nm.mockGetNamedCalls('getNodeByServer')
add_call_list = app.nm.mockGetNamedCalls('add') add_call_list = app.nm.mockGetNamedCalls('add')
...@@ -329,7 +324,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -329,7 +324,7 @@ class ClientHandlerTests(NeoTestBase):
def test_knownNodeUnknownUUIDNodeAnswerPrimaryMaster(self): def test_knownNodeUnknownUUIDNodeAnswerPrimaryMaster(self):
node = Mock({'getNodeType': MASTER_NODE_TYPE, 'getUUID': None, 'setUUID': None}) node = Mock({'getNodeType': MASTER_NODE_TYPE, 'getUUID': None, 'setUUID': None})
class App: class App:
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByServer': node, 'add': None})
primary_master_node = None primary_master_node = None
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app, self.getDispatcher()) client_handler = PrimaryBootstrapHandler(app, self.getDispatcher())
...@@ -338,9 +333,6 @@ class ClientHandlerTests(NeoTestBase): ...@@ -338,9 +333,6 @@ class ClientHandlerTests(NeoTestBase):
test_master_list = [('127.0.0.1', 10010, test_node_uuid)] test_master_list = [('127.0.0.1', 10010, test_node_uuid)]
client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list) client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list)
# Test sanity checks # Test sanity checks
getNodeByUUID_call_list = app.nm.mockGetNamedCalls('getNodeByUUID')
self.assertEqual(len(getNodeByUUID_call_list), 1)
self.assertEqual(getNodeByUUID_call_list[0].getParam(0), conn.getUUID())
getNodeByServer_call_list = app.nm.mockGetNamedCalls('getNodeByServer') getNodeByServer_call_list = app.nm.mockGetNamedCalls('getNodeByServer')
self.assertEqual(len(getNodeByServer_call_list), 1) self.assertEqual(len(getNodeByServer_call_list), 1)
self.assertEqual(getNodeByServer_call_list[0].getParam(0), test_master_list[0][:2]) self.assertEqual(getNodeByServer_call_list[0].getParam(0), test_master_list[0][:2])
...@@ -359,7 +351,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -359,7 +351,7 @@ class ClientHandlerTests(NeoTestBase):
test_node_uuid = self.getNewUUID() test_node_uuid = self.getNewUUID()
node = Mock({'getNodeType': MASTER_NODE_TYPE, 'getUUID': test_node_uuid, 'setUUID': None}) node = Mock({'getNodeType': MASTER_NODE_TYPE, 'getUUID': test_node_uuid, 'setUUID': None})
class App: class App:
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByServer': node, 'add': None})
primary_master_node = None primary_master_node = None
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app, self.getDispatcher()) client_handler = PrimaryBootstrapHandler(app, self.getDispatcher())
...@@ -367,9 +359,6 @@ class ClientHandlerTests(NeoTestBase): ...@@ -367,9 +359,6 @@ class ClientHandlerTests(NeoTestBase):
test_master_list = [('127.0.0.1', 10010, test_node_uuid)] test_master_list = [('127.0.0.1', 10010, test_node_uuid)]
client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list) client_handler.handleAnswerPrimaryMaster(conn, None, INVALID_UUID, test_master_list)
# Test sanity checks # Test sanity checks
getNodeByUUID_call_list = app.nm.mockGetNamedCalls('getNodeByUUID')
self.assertEqual(len(getNodeByUUID_call_list), 1)
self.assertEqual(getNodeByUUID_call_list[0].getParam(0), conn.getUUID())
getNodeByServer_call_list = app.nm.mockGetNamedCalls('getNodeByServer') getNodeByServer_call_list = app.nm.mockGetNamedCalls('getNodeByServer')
self.assertEqual(len(getNodeByServer_call_list), 1) self.assertEqual(len(getNodeByServer_call_list), 1)
self.assertEqual(getNodeByServer_call_list[0].getParam(0), test_master_list[0][:2]) self.assertEqual(getNodeByServer_call_list[0].getParam(0), test_master_list[0][:2])
...@@ -398,6 +387,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -398,6 +387,7 @@ class ClientHandlerTests(NeoTestBase):
class App: class App:
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None})
primary_master_node = test_primary_master_node primary_master_node = test_primary_master_node
trying_master_node = None
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app, self.getDispatcher()) client_handler = PrimaryBootstrapHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
...@@ -419,6 +409,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -419,6 +409,7 @@ class ClientHandlerTests(NeoTestBase):
class App: class App:
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None})
primary_master_node = node primary_master_node = node
trying_master_node = node
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app, self.getDispatcher()) client_handler = PrimaryBootstrapHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
...@@ -435,15 +426,15 @@ class ClientHandlerTests(NeoTestBase): ...@@ -435,15 +426,15 @@ class ClientHandlerTests(NeoTestBase):
class App: class App:
nm = Mock({'getNodeByUUID': ReturnValues(node, None), 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByUUID': ReturnValues(node, None), 'getNodeByServer': node, 'add': None})
primary_master_node = None primary_master_node = None
trying_master_node = None
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app, self.getDispatcher()) client_handler = PrimaryBootstrapHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
client_handler.handleAnswerPrimaryMaster(conn, None, test_primary_node_uuid, []) client_handler.handleAnswerPrimaryMaster(conn, None, test_primary_node_uuid, [])
# Test sanity checks # Test sanity checks
getNodeByUUID_call_list = app.nm.mockGetNamedCalls('getNodeByUUID') getNodeByUUID_call_list = app.nm.mockGetNamedCalls('getNodeByUUID')
self.assertEqual(len(getNodeByUUID_call_list), 2) self.assertEqual(len(getNodeByUUID_call_list), 1)
self.assertEqual(getNodeByUUID_call_list[0].getParam(0), conn.getUUID()) self.assertEqual(getNodeByUUID_call_list[0].getParam(0), test_primary_node_uuid)
self.assertEqual(getNodeByUUID_call_list[1].getParam(0), test_primary_node_uuid)
# Check that primary node was not updated. # Check that primary node was not updated.
self.assertTrue(app.primary_master_node is None) self.assertTrue(app.primary_master_node is None)
...@@ -453,6 +444,7 @@ class ClientHandlerTests(NeoTestBase): ...@@ -453,6 +444,7 @@ class ClientHandlerTests(NeoTestBase):
class App: class App:
nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None}) nm = Mock({'getNodeByUUID': node, 'getNodeByServer': node, 'add': None})
primary_master_node = None primary_master_node = None
trying_master_node = None
app = App() app = App()
client_handler = PrimaryBootstrapHandler(app, self.getDispatcher()) client_handler = PrimaryBootstrapHandler(app, self.getDispatcher())
conn = self.getConnection() conn = self.getConnection()
...@@ -460,9 +452,8 @@ class ClientHandlerTests(NeoTestBase): ...@@ -460,9 +452,8 @@ class ClientHandlerTests(NeoTestBase):
client_handler.handleAnswerPrimaryMaster(conn, None, test_node_uuid, test_master_list) client_handler.handleAnswerPrimaryMaster(conn, None, test_node_uuid, test_master_list)
# Test sanity checks # Test sanity checks
getNodeByUUID_call_list = app.nm.mockGetNamedCalls('getNodeByUUID') getNodeByUUID_call_list = app.nm.mockGetNamedCalls('getNodeByUUID')
self.assertEqual(len(getNodeByUUID_call_list), 2) self.assertEqual(len(getNodeByUUID_call_list), 1)
self.assertEqual(getNodeByUUID_call_list[0].getParam(0), conn.getUUID()) self.assertEqual(getNodeByUUID_call_list[0].getParam(0), test_node_uuid)
self.assertEqual(getNodeByUUID_call_list[1].getParam(0), test_node_uuid)
getNodeByServer_call_list = app.nm.mockGetNamedCalls('getNodeByServer') getNodeByServer_call_list = app.nm.mockGetNamedCalls('getNodeByServer')
self.assertEqual(len(getNodeByServer_call_list), 1) self.assertEqual(len(getNodeByServer_call_list), 1)
self.assertEqual(getNodeByServer_call_list[0].getParam(0), test_master_list[0][:2]) self.assertEqual(getNodeByServer_call_list[0].getParam(0), test_master_list[0][:2])
......
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