From 81b0822772169cb697b5994f49398e619d61a12d Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Mon, 26 Feb 2018 14:04:41 -0800 Subject: test: Use wait_until in tests where time was used for polling --- test/functional/feature_pruning.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'test/functional/feature_pruning.py') diff --git a/test/functional/feature_pruning.py b/test/functional/feature_pruning.py index 49ad7f838c..cb2dd1f6a8 100755 --- a/test/functional/feature_pruning.py +++ b/test/functional/feature_pruning.py @@ -11,7 +11,6 @@ This test takes 30 mins or more (up to 2 hours) from test_framework.test_framework import BitcoinTestFramework from test_framework.util import * -import time import os MIN_BLOCKS_TO_KEEP = 288 @@ -79,11 +78,8 @@ class PruneTest(BitcoinTestFramework): for i in range(25): mine_large_block(self.nodes[0], self.utxo_cache_0) - waitstart = time.time() - while os.path.isfile(self.prunedir+"blk00000.dat"): - time.sleep(0.1) - if time.time() - waitstart > 30: - raise AssertionError("blk00000.dat not pruned when it should be") + # Wait for blk00000.dat to be pruned + wait_until(lambda: not os.path.isfile(self.prunedir+"blk00000.dat"), timeout=30) self.log.info("Success") usage = calc_usage(self.prunedir) @@ -218,11 +214,8 @@ class PruneTest(BitcoinTestFramework): goalbestheight = first_reorg_height + 1 self.log.info("Verify node 2 reorged back to the main chain, some blocks of which it had to redownload") - waitstart = time.time() - while self.nodes[2].getblockcount() < goalbestheight: - time.sleep(0.1) - if time.time() - waitstart > 900: - raise AssertionError("Node 2 didn't reorg to proper height") + # Wait for Node 2 to reorg to proper height + wait_until(lambda: self.nodes[2].getblockcount() >= goalbestheight, timeout=900) assert(self.nodes[2].getbestblockhash() == goalbesthash) # Verify we can now have the data for a block previously pruned assert(self.nodes[2].getblock(self.forkhash)["height"] == self.forkheight) -- cgit v1.2.3 From 9d7f839a206b7392aebfa436ae0f9a29d33d2960 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Tue, 27 Feb 2018 14:55:01 -0800 Subject: test: Use os.path.join consistently in feature_pruning tests --- test/functional/feature_pruning.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional/feature_pruning.py') diff --git a/test/functional/feature_pruning.py b/test/functional/feature_pruning.py index cb2dd1f6a8..8dfa1be2fa 100755 --- a/test/functional/feature_pruning.py +++ b/test/functional/feature_pruning.py @@ -22,7 +22,7 @@ TIMESTAMP_WINDOW = 2 * 60 * 60 def calc_usage(blockdir): - return sum(os.path.getsize(blockdir+f) for f in os.listdir(blockdir) if os.path.isfile(blockdir+f)) / (1024. * 1024.) + return sum(os.path.getsize(blockdir+f) for f in os.listdir(blockdir) if os.path.isfile(os.path.join(blockdir, f))) / (1024. * 1024.) class PruneTest(BitcoinTestFramework): def set_test_params(self): @@ -69,7 +69,7 @@ class PruneTest(BitcoinTestFramework): sync_blocks(self.nodes[0:5]) def test_height_min(self): - if not os.path.isfile(self.prunedir+"blk00000.dat"): + if not os.path.isfile(os.path.join(self.prunedir, "blk00000.dat")): raise AssertionError("blk00000.dat is missing, pruning too early") self.log.info("Success") self.log.info("Though we're already using more than 550MiB, current usage: %d" % calc_usage(self.prunedir)) @@ -79,7 +79,7 @@ class PruneTest(BitcoinTestFramework): mine_large_block(self.nodes[0], self.utxo_cache_0) # Wait for blk00000.dat to be pruned - wait_until(lambda: not os.path.isfile(self.prunedir+"blk00000.dat"), timeout=30) + wait_until(lambda: not os.path.isfile(os.path.join(self.prunedir, "blk00000.dat")), timeout=30) self.log.info("Success") usage = calc_usage(self.prunedir) @@ -255,7 +255,7 @@ class PruneTest(BitcoinTestFramework): assert_equal(ret, expected_ret) def has_block(index): - return os.path.isfile(self.options.tmpdir + "/node{}/regtest/blocks/blk{:05}.dat".format(node_number, index)) + return os.path.isfile(os.path.join(self.nodes[node_number].datadir, "regtest", "blocks", "blk{:05}.dat".format(index))) # should not prune because chain tip of node 3 (995) < PruneAfterHeight (1000) assert_raises_rpc_error(-1, "Blockchain is too short for pruning", node.pruneblockchain, height(500)) -- cgit v1.2.3