Add filter counts in session tests, finish sync interrupt test

This commit is contained in:
lash 2022-03-30 05:25:26 +00:00
parent 18f9b9bd1f
commit e8decb9cb7
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 21 additions and 6 deletions

View File

@ -67,6 +67,7 @@ class MockBlockGenerator:
driver.add_block(block)
class MockConn:
"""Noop connection mocker.
@ -157,7 +158,6 @@ class MockFilter:
def filter(self, conn, block, tx):
r = False
self.contents.append((block.number, tx.index, tx.hash,))
if self.brk_hard != None:
r = True
if self.brk_hard > 0:
@ -169,6 +169,7 @@ class MockFilter:
if self.brk > 0:
r = True
self.brk -= 1
self.contents.append((block.number, tx.index, tx.hash,))
logg.debug('filter {} result {} block {}'.format(self.common_name(), r, block.number))
return r

View File

@ -80,14 +80,17 @@ class TestFilter(unittest.TestCase):
generator = MockBlockGenerator()
generator.generate([1], driver=drv)
fltr_one = MockFilter('foo', brk_hard=1)
fltr_one = MockFilter('foo')
self.store.register(fltr_one)
fltr_two = MockFilter('bar')
fltr_two = MockFilter('bar', brk_hard=1)
self.store.register(fltr_two)
with self.assertRaises(MockFilterError):
drv.run(self.conn)
self.assertEqual(len(fltr_one.contents), 1)
self.assertEqual(len(fltr_two.contents), 0)
store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler)
fltr_one = MockFilter('foo') #, brk_hard=1)
@ -98,16 +101,21 @@ class TestFilter(unittest.TestCase):
with self.assertRaises(LockError):
drv = MockDriver(store, target=1)
self.assertEqual(len(fltr_one.contents), 0)
self.assertEqual(len(fltr_two.contents), 0)
def test_driver_interrupt_filter(self):
drv = MockDriver(self.store, target=1)
generator = MockBlockGenerator()
generator.generate([1, 1], driver=drv)
fltr_one = MockFilter('foo', brk=1)
fltr_one = MockFilter('foo')
self.store.register(fltr_one)
fltr_two = MockFilter('bar')
fltr_two = MockFilter('bar', brk=1)
self.store.register(fltr_two)
fltr_three = MockFilter('baz')
self.store.register(fltr_three)
store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler)
@ -115,6 +123,10 @@ class TestFilter(unittest.TestCase):
with self.assertRaises(SyncDone):
drv.run(self.conn)
self.assertEqual(len(fltr_one.contents), 2)
self.assertEqual(len(fltr_two.contents), 2)
self.assertEqual(len(fltr_three.contents), 1)
def test_driver_interrupt_sync(self):
drv = MockDriver(self.store, interrupt_block=1, target=2)
@ -126,9 +138,9 @@ class TestFilter(unittest.TestCase):
drv.run(self.conn, interval=0.1)
self.assertEqual(len(fltr_one.contents), 3)
store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler)
fltr_one = MockFilter('foo')
store.register(fltr_one)
drv = MockDriver(store)
generator.apply(drv, offset=1)
@ -137,6 +149,8 @@ class TestFilter(unittest.TestCase):
drv.run(self.conn, interval=0.1)
self.assertEqual(e, 2)
self.assertEqual(len(fltr_one.contents), 6)
if __name__ == '__main__':
unittest.main()