Skip to content

Commit c01980a

Browse files
author
Ivan Lazarev
committed
[PBCKP-304] test dirs cleanup fixed - added logic for nodes GC and dirs cleanup
1 parent 7c6b935 commit c01980a

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

tests/helpers/ptrack_helpers.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ class ProbackupTest(object):
205205
def __init__(self, *args, **kwargs):
206206
super(ProbackupTest, self).__init__(*args, **kwargs)
207207

208+
self.nodes_to_cleanup = []
209+
208210
if isinstance(self, unittest.TestCase):
209211
self.module_name = self.id().split('.')[1]
210212
self.fname = self.id().split('.')[3]
@@ -373,11 +375,22 @@ def __init__(self, *args, **kwargs):
373375
os.environ["PGAPPNAME"] = "pg_probackup"
374376

375377
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 it 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]
380387
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+
self.nodes_to_cleanup.clear()
381394

382395
@property
383396
def pg_config_version(self):
@@ -475,6 +488,9 @@ def make_simple_node(
475488
if node.major_version >= 13:
476489
self.set_auto_conf(
477490
node, {}, 'postgresql.conf', ['wal_keep_segments'])
491+
492+
self.nodes_to_cleanup.append(node)
493+
478494
return node
479495

480496
def simple_bootstrap(self, node, role) -> None:
@@ -1689,6 +1705,15 @@ def get_bin_path(self, binary):
16891705
return testgres.get_bin_path(binary)
16901706

16911707
def clean_all(self):
1708+
# pre gc.collect() all dropped nodes
1709+
for o in gc.get_referrers(testgres.PostgresNode):
1710+
if o.__class__ is testgres.PostgresNode:
1711+
# removing node from slow_start enclosure
1712+
# after this the node is collectable by gc
1713+
o.slow_start = None
1714+
gc.collect()
1715+
1716+
# only when there are unhandled nodes left we do the cleanup for them
16921717
for o in gc.get_referrers(testgres.PostgresNode):
16931718
if o.__class__ is testgres.PostgresNode:
16941719
o.cleanup()

0 commit comments

Comments
 (0)