8000 [PBCKP-304] test dirs cleanup fixed - added logic for nodes GC and di… · postgrespro/pg_probackup@39e06f5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39e06f5

Browse files
author
Ivan Lazarev
committed
[PBCKP-304] test dirs cleanup fixed - added logic for nodes GC and dirs cleanup
1 parent 9f3f530 commit 39e06f5

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

tests/helpers/ptrack_helpers.py

Lines changed: 30 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,23 @@ 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 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]
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+
node.cleanup()
394+
self.nodes_to_cleanup.clear()
381395

382396
@property
383397
def pg_config_version(self):
@@ -475,6 +489,9 @@ def make_simple_node(
475489
if node.major_version >= 13:
476490
self.set_auto_conf(
477491
node, {}, 'postgresql.conf', ['wal_keep_segments'])
492+
493+
self.nodes_to_cleanup.append(node)
494+
478495
return node
479496

480497
def simple_bootstrap(self, node, role) -> None:
@@ -1689,6 +1706,15 @@ def get_bin_path(self, binary):
16891706
return testgres.get_bin_path(binary)
16901707

16911708
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
16921718
for o in gc.get_referrers(testgres.PostgresNode):
16931719
if o.__class__ is testgres.PostgresNode:
16941720
o.cleanup()

0 commit comments

Comments
 (0)
0