1
1
#!/usr/bin/env python3
2
- # Copyright (c) 2022 The Bitcoin Core developers
2
+ # Copyright (c) 2022-present The Bitcoin Core developers
3
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
"""Test removing undeleted pruned blk files on startup."""
6
6
7
7
import platform
8
- import os
9
8
from test_framework .test_framework import BitcoinTestFramework
10
9
10
+
11
11
class FeatureRemovePrunedFilesOnStartupTest (BitcoinTestFramework ):
12
12
def set_test_params (self ):
13
13
self .num_nodes = 1
@@ -18,38 +18,38 @@ def mine_batches(self, blocks):
18
18
for _ in range (n ):
19
19
self .generate (self .nodes [0 ], 250 )
20
20
self .generate (self .nodes [0 ], blocks % 250 )
21
- self .sync_blocks ()
22
21
23
22
def run_test (self ):
24
23
blk0 = self .nodes [0 ].blocks_path / "blk00000.dat"
25
24
rev0 = self .nodes [0 ].blocks_path / "rev00000.dat"
26
25
blk1 = self .nodes [0 ].blocks_path / "blk00001.dat"
27
26
rev1 = self .nodes [0 ].blocks_path / "rev00001.dat"
28
27
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" )
33
32
self .nodes [0 ].pruneblockchain (600 )
34
33
35
34
# Windows systems will not remove files with an open fd
36
35
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 ()
41
40
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 ()
46
45
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" )
48
47
fd1 .close ()
49
48
fd2 .close ()
50
49
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
+
53
53
54
54
if __name__ == '__main__' :
55
55
FeatureRemovePrunedFilesOnStartupTest (__file__ ).main ()
0 commit comments