Commit 23b9544d authored by Julien Muchembled's avatar Julien Muchembled

Remove dead code found by coverage

parent 1e4a4178
Pipeline #3995 skipped
...@@ -281,8 +281,8 @@ class NodeManager(object): ...@@ -281,8 +281,8 @@ class NodeManager(object):
self._address_dict.pop(node.getAddress(), None) self._address_dict.pop(node.getAddress(), None)
# - a master known by address but without UUID # - a master known by address but without UUID
self._uuid_dict.pop(node.getUUID(), None) self._uuid_dict.pop(node.getUUID(), None)
self.__dropSet(self._state_dict, node.getState(), node) self._state_dict[node.getState()].remove(node)
self.__dropSet(self._type_dict, node.getType(), node) self._type_dict[node.getType()].remove(node)
uuid = node.getUUID() uuid = node.getUUID()
if node.isMaster() and self._master_db is not None: if node.isMaster() and self._master_db is not None:
self._master_db.discard(node.getAddress()) self._master_db.discard(node.getAddress())
...@@ -305,10 +305,6 @@ class NodeManager(object): ...@@ -305,10 +305,6 @@ class NodeManager(object):
def _updateUUID(self, node, old_uuid): def _updateUUID(self, node, old_uuid):
self.__update(self._uuid_dict, old_uuid, node.getUUID(), node) self.__update(self._uuid_dict, old_uuid, node.getUUID(), node)
def __dropSet(self, set_dict, key, node):
if key in set_dict:
set_dict[key].remove(node)
def __updateSet(self, set_dict, old_key, new_key, node): def __updateSet(self, set_dict, old_key, new_key, node):
""" Update a set index from old to new key """ """ Update a set index from old to new key """
if old_key in set_dict: if old_key in set_dict:
......
...@@ -57,9 +57,6 @@ def _ask(self, conn, packet, handler=None, **kw): ...@@ -57,9 +57,6 @@ def _ask(self, conn, packet, handler=None, **kw):
handler.dispatch(conn, conn.fakeReceived()) handler.dispatch(conn, conn.fakeReceived())
return self.getHandlerData() return self.getHandlerData()
def resolving_tryToResolveConflict(oid, conflict_serial, serial, data):
return data
def failing_tryToResolveConflict(oid, conflict_serial, serial, data): def failing_tryToResolveConflict(oid, conflict_serial, serial, data):
raise ConflictError raise ConflictError
...@@ -85,10 +82,8 @@ class ClientApplicationTests(NeoUnitTestBase): ...@@ -85,10 +82,8 @@ class ClientApplicationTests(NeoUnitTestBase):
# some helpers # some helpers
def _begin(self, app, txn, tid=None): def _begin(self, app, txn, tid):
txn_context = app._txn_container.new(txn) txn_context = app._txn_container.new(txn)
if tid is None:
tid = self.makeTID()
txn_context['ttid'] = tid txn_context['ttid'] = tid
return txn_context return txn_context
...@@ -315,7 +310,7 @@ class ClientApplicationTests(NeoUnitTestBase): ...@@ -315,7 +310,7 @@ class ClientApplicationTests(NeoUnitTestBase):
app.store(oid, tid, 'DATA', None, txn) app.store(oid, tid, 'DATA', None, txn)
self.checkAskStoreObject(conn) self.checkAskStoreObject(conn)
txn_context['queue'].put((conn, packet, {})) txn_context['queue'].put((conn, packet, {}))
app.waitStoreResponses(txn_context, resolving_tryToResolveConflict) app.waitStoreResponses(txn_context, None) # no conflict in this test
self.assertEqual(txn_context['object_stored_counter_dict'][oid], self.assertEqual(txn_context['object_stored_counter_dict'][oid],
{tid: {uuid}}) {tid: {uuid}})
self.assertEqual(txn_context['cache_dict'][oid], 'DATA') self.assertEqual(txn_context['cache_dict'][oid], 'DATA')
...@@ -541,13 +536,9 @@ class ClientApplicationTests(NeoUnitTestBase): ...@@ -541,13 +536,9 @@ class ClientApplicationTests(NeoUnitTestBase):
conn.ask = lambda p, queue=None, **kw: \ conn.ask = lambda p, queue=None, **kw: \
type(p) is Packets.AskObjectUndoSerial and \ type(p) is Packets.AskObjectUndoSerial and \
queue.put((conn, undo_serial, kw)) queue.put((conn, undo_serial, kw))
def tryToResolveConflict(oid, conflict_serial, serial, data,
committedData=''):
raise Exception, 'Test called conflict resolution, but there ' \
'is no conflict in this test !'
# The undo # The undo
txn = self.beginTransaction(app, tid=tid3) txn = self.beginTransaction(app, tid=tid3)
app.undo(tid1, txn, tryToResolveConflict) app.undo(tid1, txn, None) # no conflict resolution in this test
# Checking what happened # Checking what happened
moid, mserial, mdata, mdata_serial = store_marker[0] moid, mserial, mdata, mdata_serial = store_marker[0]
self.assertEqual(moid, oid0) self.assertEqual(moid, oid0)
......
...@@ -258,23 +258,12 @@ class MasterServerElectionTests(MasterClientElectionTestBase): ...@@ -258,23 +258,12 @@ class MasterServerElectionTests(MasterClientElectionTestBase):
self.assertEqual(node.getUUID(), new_uuid) self.assertEqual(node.getUUID(), new_uuid)
self.assertNotEqual(node.getUUID(), uuid) self.assertNotEqual(node.getUUID(), uuid)
def _getNodeList(self):
return [x.asTuple() for x in self.app.nm.getList()]
def __getClient(self): def __getClient(self):
uuid = self.getClientUUID() uuid = self.getClientUUID()
conn = self.getFakeConnection(uuid=uuid, address=self.client_address) conn = self.getFakeConnection(uuid=uuid, address=self.client_address)
self.app.nm.createClient(uuid=uuid, address=self.client_address) self.app.nm.createClient(uuid=uuid, address=self.client_address)
return conn return conn
def __getMaster(self, port=1000, register=True):
uuid = self.getMasterUUID()
address = ('127.0.0.1', port)
conn = self.getFakeConnection(uuid=uuid, address=address)
if register:
self.app.nm.createMaster(uuid=uuid, address=address)
return conn
def testRequestIdentification1(self): def testRequestIdentification1(self):
""" Check with a non-master node, must be refused """ """ Check with a non-master node, must be refused """
conn = self.__getClient() conn = self.__getClient()
......
...@@ -56,6 +56,10 @@ class MasterRecoveryTests(NeoUnitTestBase): ...@@ -56,6 +56,10 @@ class MasterRecoveryTests(NeoUnitTestBase):
# Tests # Tests
def test_10_answerPartitionTable(self): def test_10_answerPartitionTable(self):
# XXX: This test does much less that it seems, because all 'for' loops
# iterate over empty lists. Currently, only testRecovery covers
# some paths in NodeManager._createNode: apart from that, we could
# delete it entirely.
recovery = self.recovery recovery = self.recovery
uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port) uuid = self.identifyToMasterNode(NodeTypes.MASTER, port=self.master_port)
# not from target node, ignore # not from target node, ignore
......
...@@ -40,7 +40,7 @@ class testTransactionManager(NeoUnitTestBase): ...@@ -40,7 +40,7 @@ class testTransactionManager(NeoUnitTestBase):
storage_2_uuid = self.getStorageUUID() storage_2_uuid = self.getStorageUUID()
oid_list = [self.makeOID(1), ] oid_list = [self.makeOID(1), ]
tm = TransactionManager(lambda tid, txn: None) tm = TransactionManager(None)
# Transaction 1: 2 storage nodes involved, one will die and the other # Transaction 1: 2 storage nodes involved, one will die and the other
# already answered node lock # already answered node lock
msg_id_1 = 1 msg_id_1 = 1
...@@ -117,7 +117,7 @@ class testTransactionManager(NeoUnitTestBase): ...@@ -117,7 +117,7 @@ class testTransactionManager(NeoUnitTestBase):
Note: this implementation might change later, for more parallelism. Note: this implementation might change later, for more parallelism.
""" """
client_uuid, client = self.makeNode(NodeTypes.CLIENT) client_uuid, client = self.makeNode(NodeTypes.CLIENT)
tm = TransactionManager(lambda tid, txn: None) tm = TransactionManager(None)
# With a requested TID, lock spans from begin to remove # With a requested TID, lock spans from begin to remove
ttid1 = self.getNextTID() ttid1 = self.getNextTID()
ttid2 = self.getNextTID() ttid2 = self.getNextTID()
...@@ -134,7 +134,7 @@ class testTransactionManager(NeoUnitTestBase): ...@@ -134,7 +134,7 @@ class testTransactionManager(NeoUnitTestBase):
def testClientDisconectsAfterBegin(self): def testClientDisconectsAfterBegin(self):
client_uuid1, node1 = self.makeNode(NodeTypes.CLIENT) client_uuid1, node1 = self.makeNode(NodeTypes.CLIENT)
tm = TransactionManager(lambda tid, txn: None) tm = TransactionManager(None)
tid1 = self.getNextTID() tid1 = self.getNextTID()
tid2 = self.getNextTID() tid2 = self.getNextTID()
tm.begin(node1, tid1) tm.begin(node1, tid1)
......
...@@ -14,13 +14,14 @@ ...@@ -14,13 +14,14 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import shutil
import unittest import unittest
from mock import Mock from mock import Mock
from neo.lib.protocol import NodeTypes, NodeStates from neo.lib.protocol import NodeTypes, NodeStates
from neo.lib.node import Node, MasterDB from neo.lib.node import Node, MasterDB
from . import NeoUnitTestBase, getTempDirectory from . import NeoUnitTestBase, getTempDirectory
from time import time from time import time
from os import chmod, mkdir, rmdir, unlink from os import chmod, mkdir, rmdir
from os.path import join, exists from os.path import join, exists
class NodesTests(NeoUnitTestBase): class NodesTests(NeoUnitTestBase):
...@@ -182,12 +183,6 @@ class NodeManagerTests(NeoUnitTestBase): ...@@ -182,12 +183,6 @@ class NodeManagerTests(NeoUnitTestBase):
self.assertEqual(self.admin.getState(), NodeStates.UNKNOWN) self.assertEqual(self.admin.getState(), NodeStates.UNKNOWN)
class MasterDBTests(NeoUnitTestBase): class MasterDBTests(NeoUnitTestBase):
def _checkMasterDB(self, path, expected_master_list):
db = list(MasterDB(path))
db_set = set(db)
# Generic sanity check
self.assertEqual(len(db), len(db_set))
self.assertEqual(db_set, set(expected_master_list))
def testInitialAccessRights(self): def testInitialAccessRights(self):
""" """
...@@ -227,9 +222,7 @@ class MasterDBTests(NeoUnitTestBase): ...@@ -227,9 +222,7 @@ class MasterDBTests(NeoUnitTestBase):
db2 = MasterDB(db_file) db2 = MasterDB(db_file)
self.assertFalse(address in db2, [x for x in db2]) self.assertFalse(address in db2, [x for x in db2])
finally: finally:
if exists(db_file): shutil.rmtree(directory)
unlink(db_file)
rmdir(directory)
def testPersistence(self): def testPersistence(self):
temp_dir = getTempDirectory() temp_dir = getTempDirectory()
...@@ -253,9 +246,7 @@ class MasterDBTests(NeoUnitTestBase): ...@@ -253,9 +246,7 @@ class MasterDBTests(NeoUnitTestBase):
self.assertFalse(address in db3, [x for x in db3]) self.assertFalse(address in db3, [x for x in db3])
self.assertTrue(address2 in db3, [x for x in db3]) self.assertTrue(address2 in db3, [x for x in db3])
finally: finally:
if exists(db_file): shutil.rmtree(directory)
unlink(db_file)
rmdir(directory)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.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