Commit eff9cc88 authored by Julien Muchembled's avatar Julien Muchembled

Rewrite tests of Storage.history() with a threaded test

parent 59c8a2bf
......@@ -777,50 +777,6 @@ class ClientApplicationTests(NeoUnitTestBase):
self.assertEqual(result[0]['id'], tid1)
self.assertEqual(result[1]['id'], tid2)
def test_history(self):
app = self.getApp()
oid = self.makeOID(1)
tid1, tid2 = self.makeTID(1), self.makeTID(2)
object_history = ( (tid1, 42), (tid2, 42),)
# object history, first is a wrong oid, second is valid
p2 = Packets.AnswerObjectHistory(oid, object_history)
extension = dumps({'k': 'v'})
# transaction history
p3 = Packets.AnswerTransactionInformation(tid2, 'u', 'd',
extension, False, (oid, ))
p4 = Packets.AnswerTransactionInformation(tid1, 'u', 'd',
extension, False, (oid, ))
p2.setId(0)
p3.setId(1)
p4.setId(2)
# faked environnement
conn = Mock({
'getNextId': 1,
'fakeGetApp': app,
'fakeReceived': ReturnValues(p3, p4),
'getAddress': ('127.0.0.1', 10010),
})
object_cells = [ Mock({}), ]
history_cells = [ Mock({}), Mock({}) ]
app.pt = Mock({
'getCellListForOID': object_cells,
'getCellListForTID': ReturnValues(history_cells, history_cells),
})
app.cp = Mock({
'iterateForObject': [(Mock(), conn)],
})
def waitResponses(queue, handler_data):
app.setHandlerData(handler_data)
app._handlePacket(Mock(), p2, handler=app.storage_handler)
app.waitResponses = waitResponses
# start test here
result = app.history(oid)
self.assertEqual(len(result), 2)
self.assertEqual(result[0]['tid'], tid2)
self.assertEqual(result[1]['tid'], tid1)
self.assertEqual(result[0]['size'], 42)
self.assertEqual(result[1]['size'], 42)
def test_connectToPrimaryNode(self):
# here we have three master nodes :
# the connection to the first will fail
......
......@@ -205,18 +205,6 @@ class StorageAnswerHandlerTests(NeoUnitTestBase):
'packed': packed,
}, ext))
def test_answerObjectHistory(self):
conn = self.getConnection()
oid = self.getOID(0)
history_list = [self.getNextTID(), self.getNextTID()]
history_set = set()
app = Mock({
'getHandlerData': history_set,
})
handler = StorageAnswersHandler(app)
handler.answerObjectHistory(conn, oid, history_list)
self.assertEqual(history_set, set(history_list))
def test_oidNotFound(self):
conn = self.getConnection()
self.assertRaises(NEOStorageNotFoundError, self.handler.oidNotFound,
......
......@@ -41,6 +41,7 @@ class Test(NEOThreadedTest):
c.root()['with_resolution'] = ob = PCounterWithResolution()
t.commit()
self.assertEqual(ob._p_changed, 0)
oid = ob._p_oid
tid1 = ob._p_serial
self.assertNotEqual(tid1, ZERO_TID)
del ob, t, c
......@@ -69,6 +70,12 @@ class Test(NEOThreadedTest):
tid3 = o1._p_serial
self.assertTrue(tid2 < tid3)
self.assertEqual(tid3, o2._p_serial)
# check history
history = c1.db().history
self.assertEqual([x['tid'] for x in history(oid, size=1)], [tid3])
self.assertEqual([x['tid'] for x in history(oid, size=10)],
[tid3, tid2, tid1])
finally:
cluster.stop()
......
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