11#!/usr/bin/env python3
2- # Copyright (c) 2022 The Bitcoin Core developers
2+ # Copyright (c) 2022-present The Bitcoin Core developers
33# Distributed under the MIT software license, see the accompanying
44# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55"""Test removing undeleted pruned blk files on startup."""
66
77import platform
8- import os
98from test_framework .test_framework import BitcoinTestFramework
109
10+
1111class FeatureRemovePrunedFilesOnStartupTest (BitcoinTestFramework ):
1212 def set_test_params (self ):
1313 self .num_nodes = 1
@@ -18,38 +18,38 @@ def mine_batches(self, blocks):
1818 for _ in range (n ):
1919 self .generate (self .nodes [0 ], 250 )
2020 self .generate (self .nodes [0 ], blocks % 250 )
21- self .sync_blocks ()
2221
2322 def run_test (self ):
2423 blk0 = self .nodes [0 ].blocks_path / "blk00000.dat"
2524 rev0 = self .nodes [0 ].blocks_path / "rev00000.dat"
2625 blk1 = self .nodes [0 ].blocks_path / "blk00001.dat"
2726 rev1 = self .nodes [0 ].blocks_path / "rev00001.dat"
2827 self .mine_batches (800 )
29- fo1 = os . open ( blk0 , os . O_RDONLY )
30- fo2 = os . open ( rev1 , os . O_RDONLY )
31- fd1 = os . fdopen ( fo1 )
32- fd2 = os . fdopen ( fo2 )
28+
29+ self . log . info ( "Open some files to check that this may delay deletion" )
30+ fd1 = open ( blk0 , "rb" )
31+ fd2 = open ( rev1 , "rb" )
3332 self .nodes [0 ].pruneblockchain (600 )
3433
3534 # Windows systems will not remove files with an open fd
3635 if platform .system () != 'Windows' :
37- assert not os . path . exists (blk0 )
38- assert not os . path . exists (rev0 )
39- assert not os . path . exists (blk1 )
40- assert not os . path . exists (rev1 )
36+ assert not blk0 . exists ()
37+ assert not rev0 . exists ()
38+ assert not blk1 . exists ()
39+ assert not rev1 . exists ()
4140 else :
42- assert os . path . exists (blk0 )
43- assert not os . path . exists (rev0 )
44- assert not os . path . exists (blk1 )
45- assert os . path . exists (rev1 )
41+ assert blk0 . exists ()
42+ assert not rev0 . exists ()
43+ assert not blk1 . exists ()
44+ assert rev1 . exists ()
4645
47- # Check that the files are removed on restart once the fds are closed
46+ self . log . info ( " Check that the files are removed on restart once the fds are closed" )
4847 fd1 .close ()
4948 fd2 .close ()
5049 self .restart_node (0 )
51- assert not os .path .exists (blk0 )
52- assert not os .path .exists (rev1 )
50+ assert not blk0 .exists ()
51+ assert not rev1 .exists ()
52+
5353
5454if __name__ == '__main__' :
5555 FeatureRemovePrunedFilesOnStartupTest (__file__ ).main ()
0 commit comments