Skip to content

Commit 6a796b2

Browse files
author
MarcoFalke
committed
Merge #10342: [tests] Improve mempool_persist test
329ac3b [tests] use wait_until in mempool_persist.py (John Newbery) Tree-SHA512: 3f5fe3dcdb5da3b10a41f7b88d29c15b79c02fbb037914b4342b77428f2afe8b342f6adacb28a9eb5549aa156cd146175389bd61909a20df3fecb88361c4779f
2 parents 23d78c4 + 329ac3b commit 6a796b2

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

test/functional/mempool_persist.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
77
By default, bitcoind will dump mempool on shutdown and
88
then reload it on startup. This can be overridden with
9-
the -persistmempool=false command line option.
9+
the -persistmempool=0 command line option.
1010
1111
Test is as follows:
1212
13-
- start node0, node1 and node2. node1 has -persistmempool=false
13+
- start node0, node1 and node2. node1 has -persistmempool=0
1414
- create 5 transactions on node2 to its own address. Note that these
1515
are not sent to node0 or node1 addresses because we don't want
1616
them to be saved in the wallet.
@@ -20,43 +20,38 @@
2020
in its mempool. Shutdown node0. This tests that by default the
2121
mempool is persistent.
2222
- startup node1. Verify that its mempool is empty. Shutdown node1.
23-
This tests that with -persistmempool=false, the mempool is not
23+
This tests that with -persistmempool=0, the mempool is not
2424
dumped to disk when the node is shut down.
25-
- Restart node0 with -persistmempool=false. Verify that its mempool is
26-
empty. Shutdown node0. This tests that with -persistmempool=false,
25+
- Restart node0 with -persistmempool=0. Verify that its mempool is
26+
empty. Shutdown node0. This tests that with -persistmempool=0,
2727
the mempool is not loaded from disk on start up.
28-
- Restart node0 with -persistmempool=true. Verify that it has 5
29-
transactions in its mempool. This tests that -persistmempool=false
28+
- Restart node0 with -persistmempool. Verify that it has 5
29+
transactions in its mempool. This tests that -persistmempool=0
3030
does not overwrite a previously valid mempool stored on disk.
3131
3232
"""
33+
import time
3334

35+
from test_framework.mininode import wait_until
3436
from test_framework.test_framework import BitcoinTestFramework
3537
from test_framework.util import *
3638

3739
class MempoolPersistTest(BitcoinTestFramework):
3840

3941
def __init__(self):
4042
super().__init__()
43+
# We need 3 nodes for this test. Node1 does not have a persistent mempool.
4144
self.num_nodes = 3
4245
self.setup_clean_chain = False
43-
44-
def setup_network(self):
45-
# We need 3 nodes for this test. Node1 does not have a persistent mempool.
46-
self.nodes = []
47-
self.nodes.append(start_node(0, self.options.tmpdir))
48-
self.nodes.append(start_node(1, self.options.tmpdir, ["-persistmempool=false"]))
49-
self.nodes.append(start_node(2, self.options.tmpdir))
50-
connect_nodes_bi(self.nodes, 0, 2)
51-
connect_nodes_bi(self.nodes, 1, 2)
52-
self.is_network_split = False
46+
self.extra_args = [[], ["-persistmempool=0"], []]
5347

5448
def run_test(self):
5549
chain_height = self.nodes[0].getblockcount()
5650
assert_equal(chain_height, 200)
5751

5852
self.log.debug("Mine a single block to get out of IBD")
5953
self.nodes[0].generate(1)
54+
self.sync_all()
6055

6156
self.log.debug("Send 5 transactions from node2 (to its own address)")
6257
for i in range(5):
@@ -72,20 +67,24 @@ def run_test(self):
7267
self.nodes = []
7368
self.nodes.append(start_node(0, self.options.tmpdir))
7469
self.nodes.append(start_node(1, self.options.tmpdir))
75-
assert_equal(len(self.nodes[0].getrawmempool()), 5)
70+
# Give bitcoind a second to reload the mempool
71+
time.sleep(1)
72+
assert wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
7673
assert_equal(len(self.nodes[1].getrawmempool()), 0)
7774

78-
self.log.debug("Stop-start node0 with -persistmempool=false. Verify that it doesn't load its mempool.dat file.")
75+
self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
7976
stop_nodes(self.nodes)
8077
self.nodes = []
81-
self.nodes.append(start_node(0, self.options.tmpdir, ["-persistmempool=false"]))
78+
self.nodes.append(start_node(0, self.options.tmpdir, ["-persistmempool=0"]))
79+
# Give bitcoind a second to reload the mempool
80+
time.sleep(1)
8281
assert_equal(len(self.nodes[0].getrawmempool()), 0)
8382

8483
self.log.debug("Stop-start node0. Verify that it has the transactions in its mempool.")
8584
stop_nodes(self.nodes)
8685
self.nodes = []
8786
self.nodes.append(start_node(0, self.options.tmpdir))
88-
assert_equal(len(self.nodes[0].getrawmempool()), 5)
87+
assert wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
8988

9089
if __name__ == '__main__':
9190
MempoolPersistTest().main()

0 commit comments

Comments
 (0)