Complete rocksdb test

This commit is contained in:
lash 2022-04-20 16:36:06 +00:00
parent 4bda7522ab
commit 05898a7e00
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 30 additions and 15 deletions

View File

@ -228,8 +228,6 @@ class SyncStore:
state_bytes = sync_state_serialize(item.cursor, 0, -1)
self.state.put(str(item.cursor), state_bytes)
logg.debug('item {}'.format(self.state.state(item.state_key)))
def load(self, target):
self.state.sync(self.state.NEW)

View File

@ -50,13 +50,17 @@ class SyncRocksDbStore(SyncStore):
def get_target(self):
self.target_db.get('target')
v = self.target_db.get('target')
if v != None:
self.target = int(v)
def set_target(self, v):
self.target_db.put('target')
self.target_db.put('target', str(v))
self.target = v
def disconnect(self):
super(SyncRocksDbStore, self).disconnect()
def stop(self, item):
if item != None:
super(SyncRocksDbStore, self).stop(item)
self.factory.close()

View File

@ -267,3 +267,12 @@ class MockChainInterfaceConn(MockConn):
def handle_receipt(self, hsh):
return {}
class MockItem:
def __init__(self, target, offset, cursor, state_key):
self.target = target
self.offset = offset
self.cursor = cursor
self.state_key = state_key

View File

@ -14,7 +14,10 @@ from chainsyncer.error import (
IncompleteFilterError,
SyncDone,
)
from chainsyncer.unittest import MockFilter
from chainsyncer.unittest import (
MockFilter,
MockItem,
)
logg = logging.getLogger(__name__)
@ -50,6 +53,7 @@ class TestStoreBase(unittest.TestCase):
def t_default(self):
bogus_item = MockItem(0, 0, 0, 0)
store = self.store_factory()
fp = os.path.join(self.path, store.session_id)
@ -66,19 +70,19 @@ class TestStoreBase(unittest.TestCase):
fpd = os.path.realpath(fpd)
self.assertEqual(fpd, fp)
store.disconnect()
store.stop(bogus_item)
store = self.store_factory()
fpr = os.path.join(self.path, session_id)
self.assertEqual(fp, fpr)
self.assertTrue(store.is_default)
store.disconnect()
store.stop(bogus_item)
store = self.store_factory('default')
fpr = os.path.join(self.path, session_id)
self.assertEqual(fp, fpr)
self.assertTrue(store.is_default)
store.disconnect()
store.stop(bogus_item)
store = self.store_factory('foo')
fpf = os.path.join(self.path, 'foo')
st = os.stat(fpf)
@ -87,11 +91,12 @@ class TestStoreBase(unittest.TestCase):
def t_store_start(self):
bogus_item = MockItem(0, 0, 0, 0)
store = self.store_factory()
store.start(42)
self.assertTrue(store.first)
store.disconnect()
store.stop(bogus_item)
store = self.store_factory()
store.start()
self.assertFalse(store.first)
@ -221,13 +226,13 @@ class TestStoreBase(unittest.TestCase):
o.next(advance_block=True)
session.stop(o)
store.disconnect()
store = self.store_factory('foo')
store.start()
o = store.get(2)
def t_sync_history_interrupted(self):
bogus_item = MockItem(0, 0, 0, 0)
store = self.store_factory('foo')
session = SyncSession(store)
@ -237,7 +242,7 @@ class TestStoreBase(unittest.TestCase):
o.next(advance_block=True)
session.stop(o)
store.disconnect()
store.stop(bogus_item)
store = self.store_factory('foo')
store.start()
o = store.get(0)
@ -246,8 +251,7 @@ class TestStoreBase(unittest.TestCase):
o.next(advance_block=True)
o.next(advance_block=True)
session.stop(o)
store.disconnect()
store.stop(bogus_item)
store = self.store_factory('foo')
store.start()
self.assertEqual(o.cursor, 4)