1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-11-24 08:52:38 +02:00

[PBCKP-304] extended testgres.PosgresNode to filter excessive close() and its log entries calls

This commit is contained in:
Ivan Lazarev 2022-11-15 17:45:28 +03:00
parent e2b4549887
commit 9924ab0142

View File

@ -140,7 +140,7 @@ class ProbackupException(Exception):
return '\n ERROR: {0}\n CMD: {1}'.format(repr(self.message), self.cmd)
def slow_start(self, replica=False):
def _slow_start(self, replica=False):
# wait for https://github.com/postgrespro/testgres/pull/50
# self.start()
@ -174,7 +174,7 @@ def slow_start(self, replica=False):
sleep(0.5)
def is_test_result_ok(test_case):
def _is_test_result_ok(test_case):
# sources of solution:
# 1. python versions 2.7 - 3.10, verified on 3.10, 3.7, 2.7, taken from:
# https://tousu.in/qa/?qa=555402/unit-testing-getting-pythons-unittest-results-in-a-teardown-method&show=555403#a555403
@ -197,6 +197,28 @@ def is_test_result_ok(test_case):
return ok
class PostgresNodeExtended(testgres.PostgresNode):
def __init__(self, base_dir=None, *args, **kwargs):
super(PostgresNodeExtended, self).__init__(name='test', base_dir=base_dir, *args, **kwargs)
self.is_started = False
def slow_start(self, replica=False):
_slow_start(self, replica=replica)
def start(self, *args, **kwargs):
if not self.is_started:
super(PostgresNodeExtended, self).start(*args, **kwargs)
self.is_started = True
return self
def stop(self, *args, **kwargs):
if self.is_started:
result = super(PostgresNodeExtended, self).stop(*args, **kwargs)
self.is_started = False
return result
class ProbackupTest(object):
# Class attributes
enterprise = is_enterprise()
@ -375,7 +397,7 @@ class ProbackupTest(object):
os.environ["PGAPPNAME"] = "pg_probackup"
def tearDown(self):
if is_test_result_ok(self):
if _is_test_result_ok(self):
for node in self.nodes_to_cleanup:
node.cleanup()
self.del_test_dir(self.module_name, self.fname)
@ -418,10 +440,10 @@ class ProbackupTest(object):
shutil.rmtree(real_base_dir, ignore_errors=True)
os.makedirs(real_base_dir)
node = testgres.get_new_node('test', base_dir=real_base_dir)
# bound method slow_start() to 'node' class instance
node.slow_start = slow_start.__get__(node)
node = PostgresNodeExtended(base_dir=real_base_dir)
node.should_rm_dirs = True
self.nodes_to_cleanup.append(node)
return node
def make_simple_node(
@ -485,8 +507,6 @@ class ProbackupTest(object):
self.set_auto_conf(
node, {}, 'postgresql.conf', ['wal_keep_segments'])
self.nodes_to_cleanup.append(node)
return node
def simple_bootstrap(self, node, role) -> None: