From a4909f54e44f5aea28ad5ddad85229f188561e44 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 31 Mar 2020 10:30:36 -0400 Subject: [PATCH] test reorg count metric --- .../test_blockchain_reorganization.py | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/integration/blockchain/test_blockchain_reorganization.py b/tests/integration/blockchain/test_blockchain_reorganization.py index b271966df..2204fd918 100644 --- a/tests/integration/blockchain/test_blockchain_reorganization.py +++ b/tests/integration/blockchain/test_blockchain_reorganization.py @@ -1,8 +1,9 @@ import logging -from lbry.testcase import IntegrationTestCase +from lbry.testcase import CommandTestCase +from lbry.wallet.server.prometheus import REORG_COUNT -class BlockchainReorganizationTests(IntegrationTestCase): +class BlockchainReorganizationTests(CommandTestCase): VERBOSITY = logging.WARN @@ -13,21 +14,24 @@ class BlockchainReorganizationTests(IntegrationTestCase): ) async def test_reorg(self): + REORG_COUNT.set(0) # invalidate current block, move forward 2 - self.assertEqual(self.ledger.headers.height, 200) - await self.assertBlockHash(200) - await self.blockchain.invalidate_block((await self.ledger.headers.hash(200)).decode()) + self.assertEqual(self.ledger.headers.height, 206) + await self.assertBlockHash(206) + await self.blockchain.invalidate_block((await self.ledger.headers.hash(206)).decode()) await self.blockchain.generate(2) - await self.ledger.on_header.where(lambda e: e.height == 201) - self.assertEqual(self.ledger.headers.height, 201) - await self.assertBlockHash(200) - await self.assertBlockHash(201) + await self.ledger.on_header.where(lambda e: e.height == 207) + self.assertEqual(self.ledger.headers.height, 207) + await self.assertBlockHash(206) + await self.assertBlockHash(207) + self.assertEqual(1, REORG_COUNT._samples()[0][2]) # invalidate current block, move forward 3 - await self.blockchain.invalidate_block((await self.ledger.headers.hash(200)).decode()) + await self.blockchain.invalidate_block((await self.ledger.headers.hash(206)).decode()) await self.blockchain.generate(3) - await self.ledger.on_header.where(lambda e: e.height == 202) - self.assertEqual(self.ledger.headers.height, 202) - await self.assertBlockHash(200) - await self.assertBlockHash(201) - await self.assertBlockHash(202) + await self.ledger.on_header.where(lambda e: e.height == 208) + self.assertEqual(self.ledger.headers.height, 208) + await self.assertBlockHash(206) + await self.assertBlockHash(207) + await self.assertBlockHash(208) + self.assertEqual(2, REORG_COUNT._samples()[0][2])