Commit 2553b1c9 authored by Julien Muchembled's avatar Julien Muchembled

client: remove useless calls to time.time()

parent b70de293
......@@ -95,25 +95,17 @@ class ConnectionPool(object):
def notifyFailure(self, node):
self._notifyFailure(node.getUUID(), time.time() + MAX_FAILURE_AGE)
def _notifyFailure(self, uuid, at):
self.node_failure_dict[uuid] = at
self.node_failure_dict[node.getUUID()] = time.time() + MAX_FAILURE_AGE
def getCellSortKey(self, cell):
return self._getCellSortKey(cell.getUUID(), time.time())
def _getCellSortKey(self, uuid, now):
uuid = cell.getUUID()
if uuid in self.connection_dict:
failure = self.node_failure_dict.get(uuid)
if failure is None or failure < now:
result = CELL_GOOD
result = CELL_FAILED
return result
failure = self.node_failure_dict.get(uuid)
if failure is None or failure < time.time():
return CELL_GOOD
def getConnForCell(self, cell):
......@@ -14,12 +14,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <>.
import unittest
import time, unittest
from mock import Mock, ReturnValues
from .. import NeoUnitTestBase
from import ConnectionPool
from neo.client.exception import NEOStorageError
from neo.client import pool
class ConnectionPoolTests(NeoUnitTestBase):
......@@ -47,16 +48,22 @@ class ConnectionPoolTests(NeoUnitTestBase):
# TODO: test getConnForNode (requires splitting complex functionalities)
def test_CellSortKey(self):
pool = ConnectionPool(None)
cp = ConnectionPool(None)
node_uuid_1 = self.getStorageUUID()
node_uuid_2 = self.getStorageUUID()
node_uuid_3 = self.getStorageUUID()
# We are connected to node 1
pool.connection_dict[node_uuid_1] = None
cp.connection_dict[node_uuid_1] = None
def uuid_now(func, uuid, now):
pool.time = Mock({'time': now})
return func(Mock({'getUUID': uuid}))
pool.time = time
# A connection to node 3 failed, will be forgotten at 5
pool._notifyFailure(node_uuid_3, 5)
getCellSortKey = pool._getCellSortKey
uuid_now(cp.notifyFailure, node_uuid_3, 5 - pool.MAX_FAILURE_AGE)
def getCellSortKey(*args):
return uuid_now(cp.getCellSortKey, *args)
# At 0, key values are not ambiguous
self.assertTrue(getCellSortKey(node_uuid_1, 0) < getCellSortKey(
node_uuid_2, 0) < getCellSortKey(node_uuid_3, 0))
......@@ -743,8 +743,8 @@ class NEOCluster(object):
def extraCellSortKey(self, key):
return Patch(self.client.cp, _getCellSortKey=lambda orig, *args:
(orig(*args), key(*args)))
return Patch(self.client.cp, getCellSortKey=lambda orig, cell:
(orig(cell), key(cell)))
class NEOThreadedTest(NeoTestBase):
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