more resilient test

This commit is contained in:
Lex Berezhny 2020-06-10 15:25:45 -04:00
parent 147b9d5ad1
commit a39f87b3c5
3 changed files with 48 additions and 36 deletions

View file

@ -87,7 +87,7 @@ def process_claimtrie(heights):
done += chunk_size done += chunk_size
p.step(done) p.step(done)
with progress(Event.CLAIM_UPDATE, 250) as p, context().connection.begin(): with progress(Event.TRIE_UPDATE, 250) as p, context().connection.begin():
claims = chain.db.sync_get_claims() claims = chain.db.sync_get_claims()
p.start(len(claims)) p.start(len(claims))
done = 0 done = 0

View file

@ -123,10 +123,20 @@ class TestMultiBlockFileSyncAndEvents(AsyncioTestCase):
@staticmethod @staticmethod
def extract_events(name, events): def extract_events(name, events):
return sorted([ return sorted([
(p['data'].get('block_file'), p['data']['step'], p['data']['total']) [p['data'].get('block_file'), p['data']['step'], p['data']['total']]
for p in events if p['event'].endswith(name) for p in events if p['event'].endswith(name)
]) ])
def assertEventsAlmostEqual(self, actual, expected):
# this is needed because the sample tx data created
# by lbrycrd does not have deterministic number of TXIs,
# which throws off the progress reporting steps
# adjust the actual to match expected if it's only off by 1
for e, a in zip(expected, actual):
if a[1] != e[1] and abs(a[1]-e[1]) <= 1:
a[1] = e[1]
self.assertEqual(expected, actual)
async def test_multi_block_file_sync(self): async def test_multi_block_file_sync(self):
self.assertEqual( self.assertEqual(
[(0, 191, 280), (1, 89, 178), (2, 12, 24)], [(0, 191, 280), (1, 89, 178), (2, 12, 24)],
@ -153,39 +163,39 @@ class TestMultiBlockFileSyncAndEvents(AsyncioTestCase):
) )
self.assertEqual( self.assertEqual(
self.extract_events('block.read', events), [ self.extract_events('block.read', events), [
(0, 0, 191), [0, 0, 191],
(0, 100, 191), [0, 100, 191],
(0, 191, 191), [0, 191, 191],
(1, 0, 89), [1, 0, 89],
(1, 89, 89), [1, 89, 89],
(2, 0, 12), [2, 0, 12],
(2, 12, 12), [2, 12, 12],
] ]
) )
self.assertEqual( self.assertEventsAlmostEqual(
self.extract_events('block.save', events), [ self.extract_events('block.save', events), [
(0, 0, 280), [0, 0, 280],
(0, 19, 280), [0, 19, 280],
(0, 47, 280), [0, 47, 280],
(0, 267, 280), [0, 267, 280],
(0, 278, 280), [0, 278, 280],
(0, 280, 280), [0, 280, 280],
(1, 0, 178), [1, 0, 178],
(1, 6, 178), [1, 6, 178],
(1, 19, 178), [1, 19, 178],
(1, 166, 178), [1, 166, 178],
(1, 175, 178), [1, 175, 178],
(1, 178, 178), [1, 178, 178],
(2, 0, 24), [2, 0, 24],
(2, 1, 24), [2, 1, 24],
(2, 21, 24), [2, 21, 24],
(2, 22, 24), [2, 22, 24],
(2, 24, 24) [2, 24, 24]
] ]
) )
claim_events = self.extract_events('claim.update', events) claim_events = self.extract_events('claim.update', events)
self.assertEqual((1000, 3610), claim_events[10][1:]) self.assertEqual([3402, 3610], claim_events[2][1:])
self.assertEqual((3610, 3610), claim_events[-1][1:]) self.assertEqual([3610, 3610], claim_events[-1][1:])
events.clear() events.clear()
await self.sync.advance() # should be no-op await self.sync.advance() # should be no-op
@ -210,14 +220,14 @@ class TestMultiBlockFileSyncAndEvents(AsyncioTestCase):
) )
self.assertEqual( self.assertEqual(
self.extract_events('block.read', events), [ self.extract_events('block.read', events), [
(2, 0, 1), [2, 0, 1],
(2, 1, 1), [2, 1, 1],
] ]
) )
self.assertEqual( self.assertEqual(
self.extract_events('block.save', events), [ self.extract_events('block.save', events), [
(2, 0, 1), [2, 0, 1],
(2, 1, 1), [2, 1, 1],
] ]
) )
@ -304,19 +314,19 @@ class TestBasicSyncScenarios(BaseSyncTestCase):
async def test_claim_create_update_and_delete(self): async def test_claim_create_update_and_delete(self):
txid = await self.claim_name('foo', '0.01') txid = await self.claim_name('foo', '0.01')
await self.generate(1) await self.generate(1)
claims, _, _ = await self.db.search_claims() claims = await self.db.search_claims()
self.assertEqual(1, len(claims)) self.assertEqual(1, len(claims))
self.assertEqual(claims[0].claim_name, 'foo') self.assertEqual(claims[0].claim_name, 'foo')
self.assertEqual(dewies_to_lbc(claims[0].amount), '0.01') self.assertEqual(dewies_to_lbc(claims[0].amount), '0.01')
txid = await self.claim_update(await self.get_transaction(txid), '0.02') txid = await self.claim_update(await self.get_transaction(txid), '0.02')
await self.generate(1) await self.generate(1)
claims, _, _ = await self.db.search_claims() claims = await self.db.search_claims()
self.assertEqual(1, len(claims)) self.assertEqual(1, len(claims))
self.assertEqual(claims[0].claim_name, 'foo') self.assertEqual(claims[0].claim_name, 'foo')
self.assertEqual(dewies_to_lbc(claims[0].amount), '0.02') self.assertEqual(dewies_to_lbc(claims[0].amount), '0.02')
await self.claim_abandon(await self.get_transaction(txid)) await self.claim_abandon(await self.get_transaction(txid))
await self.generate(1) await self.generate(1)
claims, _, _ = await self.db.search_claims() claims = await self.db.search_claims()
self.assertEqual(0, len(claims)) self.assertEqual(0, len(claims))

View file

@ -11,6 +11,8 @@ passenv =
commands = commands =
blockchain: coverage run -p --rcfile={toxinidir}/setup.cfg -m unittest -vv integration.blockchain.test_claim_commands.ChannelCommands.test_create_channel_names {posargs} blockchain: coverage run -p --rcfile={toxinidir}/setup.cfg -m unittest -vv integration.blockchain.test_claim_commands.ChannelCommands.test_create_channel_names {posargs}
blockchain: coverage run -p --rcfile={toxinidir}/setup.cfg -m unittest -vv integration.blockchain.test_blockchain.TestBlockchainEvents {posargs} blockchain: coverage run -p --rcfile={toxinidir}/setup.cfg -m unittest -vv integration.blockchain.test_blockchain.TestBlockchainEvents {posargs}
blockchain: coverage run -p --rcfile={toxinidir}/setup.cfg -m unittest -vv integration.blockchain.test_blockchain.TestMultiBlockFileSyncAndEvents {posargs}
blockchain: coverage run -p --rcfile={toxinidir}/setup.cfg -m unittest -vv integration.blockchain.test_blockchain.TestBasicSyncScenarios {posargs}
#blockchain: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.blockchain {posargs} #blockchain: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.blockchain {posargs}
#datanetwork: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.datanetwork {posargs} #datanetwork: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.datanetwork {posargs}
#other: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.other {posargs} #other: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.other {posargs}