@@ -205,6 +205,8 @@ class ProbackupTest(object):
205
205
def __init__ (self , * args , ** kwargs ):
206
206
super (ProbackupTest , self ).__init__ (* args , ** kwargs )
207
207
208
+ self .nodes_to_cleanup = []
209
+
208
210
if isinstance (self , unittest .TestCase ):
209
211
self .module_name = self .id ().split ('.' )[1 ]
210
212
self .fname = self .id ().split ('.' )[3 ]
@@ -373,11 +375,23 @@ def __init__(self, *args, **kwargs):
373
375
os .environ ["PGAPPNAME" ] = "pg_probackup"
374
376
375
377
def tearDown (self ):
376
- if isinstance (self , unittest .TestCase ):
377
- module_name = self .id ().split ('.' )[1 ]
378
- fname = self .id ().split ('.' )[3 ]
379
- if is_test_result_ok (self ):
378
+ if is_test_result_ok (self ):
379
+ for node in self .nodes_to_cleanup :
380
+ node .cleanup ()
381
+ # we do clear refs to nodes to gather them by gc inside self.del_test_dir()
382
+ self .nodes_to_cleanup .clear ()
383
+
384
+ if isinstance (self , unittest .TestCase ):
385
+ module_name = self .id ().split ('.' )[1 ]
386
+ fname = self .id ().split ('.' )[3 ]
380
387
self .del_test_dir (module_name , fname )
388
+ else :
389
+ for node in self .nodes_to_cleanup :
390
+ # TODO VERIFY do we want to remain failed test's db data for further investigations?
391
+ # TODO VERIFY or just to leave logs only without node/data?
392
+ # node._try_shutdown(max_attempts=1)
393
+ node .cleanup ()
394
+ self .nodes_to_cleanup .clear ()
381
395
382
396
@property
383
397
def pg_config_version (self ):
@@ -475,6 +489,9 @@ def make_simple_node(
475
489
if node .major_version >= 13 :
476
490
self .set_auto_conf (
477
491
node , {}, 'postgresql.conf' , ['wal_keep_segments' ])
492
+
493
+ self .nodes_to_cleanup .append (node )
494
+
478
495
return node
479
496
480
497
def simple_bootstrap (self , node , role ) -> None :
@@ -1689,6 +1706,15 @@ def get_bin_path(self, binary):
1689
1706
return testgres .get_bin_path (binary )
1690
1707
1691
1708
def clean_all (self ):
1709
+ # pre gc.collect() all dropped nodes
1710
+ for o in gc .get_referrers (testgres .PostgresNode ):
1711
+ if o .__class__ is testgres .PostgresNode :
1712
+ # removing node from slow_start enclosure
1713
+ # after this the node is collectable by gc
1714
+ o .slow_start = None
1715
+ gc .collect ()
1716
+
1717
+ # only when there are unhandled nodes left we do the cleanup for them
1692
1718
for o in gc .get_referrers (testgres .PostgresNode ):
1693
1719
if o .__class__ is testgres .PostgresNode :
1694
1720
o .cleanup ()
0 commit comments