Skip to content

Commit 3141eab

Browse files
committed
test: add functional test for ScanAndUnlinkAlreadyPrunedFiles
1 parent e252909 commit 3141eab

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2022 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test removing undeleted pruned blk files on startup."""
6+
7+
import os
8+
from test_framework.test_framework import BitcoinTestFramework
9+
10+
class FeatureRemovePrunedFilesOnStartupTest(BitcoinTestFramework):
11+
def set_test_params(self):
12+
self.num_nodes = 1
13+
self.extra_args = [["-fastprune", "-prune=1"]]
14+
15+
def mine_batches(self, blocks):
16+
n = blocks // 250
17+
for _ in range(n):
18+
self.generate(self.nodes[0], 250)
19+
self.generate(self.nodes[0], blocks % 250)
20+
self.sync_blocks()
21+
22+
def run_test(self):
23+
blk0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00000.dat')
24+
rev0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'rev00000.dat')
25+
blk1 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00001.dat')
26+
rev1 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'rev00001.dat')
27+
self.mine_batches(800)
28+
fo1 = os.open(blk0, os.O_RDONLY)
29+
fo2 = os.open(rev1, os.O_RDONLY)
30+
fd1 = os.fdopen(fo1)
31+
fd2 = os.fdopen(fo2)
32+
self.nodes[0].pruneblockchain(600)
33+
34+
# Windows systems will not remove files with an open fd
35+
if os.name != 'nt':
36+
assert not os.path.exists(blk0)
37+
assert not os.path.exists(rev0)
38+
assert not os.path.exists(blk1)
39+
assert not os.path.exists(rev1)
40+
else:
41+
assert os.path.exists(blk0)
42+
assert not os.path.exists(rev0)
43+
assert not os.path.exists(blk1)
44+
assert os.path.exists(rev1)
45+
46+
# Check that the files are removed on restart once the fds are closed
47+
fd1.close()
48+
fd2.close()
49+
self.restart_node(0)
50+
assert not os.path.exists(blk0)
51+
assert not os.path.exists(rev1)
52+
53+
if __name__ == '__main__':
54+
FeatureRemovePrunedFilesOnStartupTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
'p2p_permissions.py',
338338
'feature_blocksdir.py',
339339
'wallet_startup.py',
340+
'feature_remove_pruned_files_on_startup.py',
340341
'p2p_i2p_ports.py',
341342
'p2p_i2p_sessions.py',
342343
'feature_config_args.py',

0 commit comments

Comments
 (0)