Commit 5b66a6a7 authored by Julien Muchembled's avatar Julien Muchembled

qa: rewrite test checking read-locks

parent 327bb1c0
......@@ -16,12 +16,11 @@
import unittest
from mock import Mock, ReturnValues
from collections import deque
from .. import NeoUnitTestBase
from neo.storage.app import Application
from neo.storage.handlers.client import ClientOperationHandler
from neo.lib.util import p64
from neo.lib.protocol import INVALID_TID, INVALID_OID, Packets, LockState
from neo.lib.protocol import INVALID_TID, Packets, LockState
class StorageClientHandlerTests(NeoUnitTestBase):
......@@ -31,11 +30,6 @@ class StorageClientHandlerTests(NeoUnitTestBase):
# create an application object
config = self.getStorageConfiguration(master_number=1)
self.app = Application(config)
self.app.transaction_dict = {}
self.app.store_lock_dict = {}
self.app.load_lock_dict = {}
self.app.event_queue = deque()
self.app.event_queue_dict = {}
self.app.tm = Mock({'__contains__': True})
# handler
self.operation = ClientOperationHandler(self.app)
......@@ -60,19 +54,6 @@ class StorageClientHandlerTests(NeoUnitTestBase):
self.operation.askTransactionInformation(conn, INVALID_TID)
self.checkErrorPacket(conn)
def test_24_askObject1(self):
# delayed response
conn = self._getConnection()
self.app.dm = Mock()
self.app.tm = Mock({'loadLocked': True})
self.app.load_lock_dict[INVALID_OID] = object()
self.assertEqual(len(self.app.event_queue), 0)
self.operation.askObject(conn, oid=INVALID_OID,
serial=INVALID_TID, tid=INVALID_TID)
self.assertEqual(len(self.app.event_queue), 1)
self.checkNoPacketSent(conn)
self.assertEqual(len(self.app.dm.mockGetNamedCalls('getObject')), 0)
def test_25_askTIDs1(self):
# invalid offsets => error
app = self.app
......@@ -110,7 +91,6 @@ class StorageClientHandlerTests(NeoUnitTestBase):
undone_tid = self.getNextTID()
# Keep 2 entries here, so we check findUndoTID is called only once.
oid_list = map(p64, (1, 2))
obj2_data = [] # Marker
self.app.tm = Mock({
'getObjectFromTransaction': None,
})
......
......@@ -431,6 +431,43 @@ class Test(NEOThreadedTest):
finally:
cluster.stop()
def testDelayedLoad(self):
"""
Check that a storage node delays reads from the database,
when the requested data may still be in a temporary place.
"""
l = threading.Lock()
l.acquire()
idle = []
def askObject(orig, *args):
orig(*args)
idle.append(cluster.storage.em.isIdle())
l.release()
cluster = NEOCluster()
try:
cluster.start()
t, c = cluster.getTransaction()
r = c.root()
r[''] = ''
with Patch(ClientOperationHandler, askObject=askObject):
with cluster.master.filterConnection(cluster.storage) as m2s:
m2s.add(lambda conn, packet: # delay unlock
isinstance(packet, Packets.NotifyUnlockInformation))
t.commit()
c.cacheMinimize()
cluster.client._cache.clear()
load = self.newThread(r._p_activate)
l.acquire()
l.acquire()
# The request from the client is processed again
# (upon reception on unlock notification from the master),
# once exactly, and now with success.
load.join()
self.assertEqual(idle, [1, 0])
self.assertIn('', r)
finally:
cluster.stop()
def test_notifyNodeInformation(self):
# translated from MasterNotificationsHandlerTests
# (neo.tests.client.testMasterHandler)
......
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