Skip to content

Commit 24bd657

Browse files
committed
make separate function for node creation in catchup tests (make_empty_node)
1 parent 02aa321 commit 24bd657

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

tests/catchup.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ def test_multithread_local_transfer(self):
3636
"CREATE TABLE ultimate_question AS SELECT 42 AS answer")
3737
result = source_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
3838

39+
dest_pg = self.make_empty_node(os.path.join(module_name, fname, 'dst'))
3940
dest_pg = self.catchup_node(
4041
backup_mode = 'FULL',
4142
source_pgdata = source_pg.data_dir,
42-
destination_base_dir = os.path.join(module_name, fname, 'dst'),
43+
destination_node = dest_pg,
4344
options = ['-d', 'postgres', '-p', str(source_pg.port), '--stream', '-j', '4']
4445
)
4546
source_pg.stop()
@@ -69,10 +70,11 @@ def test_multithread_remote_transfer(self):
6970
"CREATE TABLE ultimate_question AS SELECT 42 AS answer")
7071
result = source_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
7172

73+
dest_pg = self.make_empty_node(os.path.join(module_name, fname, 'dst'))
7274
dest_pg = self.catchup_node(
7375
backup_mode = 'FULL',
7476
source_pgdata = source_pg.data_dir,
75-
destination_base_dir = os.path.join(module_name, fname, 'dst'),
77+
destination_node = dest_pg,
7678
options = ['-d', 'postgres', '-p', str(source_pg.port), '--stream', '-j', '4'])
7779
source_pg.stop()
7880

@@ -109,10 +111,11 @@ def test_remote_catchup(self):
109111
source_pg.safe_psql("postgres", "CREATE TABLE ultimate_question(answer int)")
110112

111113
# make clean shutdowned lagging behind replica
114+
dest_pg = self.make_empty_node(os.path.join(module_name, fname, 'dst'))
112115
dest_pg = self.catchup_node(
113116
backup_mode = 'FULL',
114117
source_pgdata = source_pg.data_dir,
115-
destination_base_dir = os.path.join(module_name, fname, 'dst'),
118+
destination_node = dest_pg,
116119
options = ['-d', 'postgres', '-p', str(source_pg.port), '--stream'])
117120
self.set_replica(source_pg, dest_pg)
118121
dest_pg.slow_start(replica = True)
@@ -129,9 +132,8 @@ def test_remote_catchup(self):
129132
self.catchup_node(
130133
backup_mode = 'PTRACK',
131134
source_pgdata = source_pg.data_dir,
132-
destination_base_dir = os.path.join(module_name, fname, 'dst'),
133-
options = ['-d', 'postgres', '-p', str(source_pg.port), '--stream'],
134-
node = dest_pg)
135+
destination_node = dest_pg,
136+
options = ['-d', 'postgres', '-p', str(source_pg.port), '--stream'])
135137

136138
# stop replication
137139
source_pg.stop()

tests/helpers/ptrack_helpers.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,9 @@ def pg_config_version(self):
335335
# print('PGPROBACKUP_SSH_USER is not set')
336336
# exit(1)
337337

338-
def make_simple_node(
338+
def make_empty_node(
339339
self,
340-
base_dir=None,
341-
set_replication=False,
342-
ptrack_enable=False,
343-
initdb_params=[],
344-
pg_options={}):
345-
340+
base_dir=None):
346341
real_base_dir = os.path.join(self.tmp_path, base_dir)
347342
shutil.rmtree(real_base_dir, ignore_errors=True)
348343
os.makedirs(real_base_dir)
@@ -351,6 +346,17 @@ def make_simple_node(
351346
# bound method slow_start() to 'node' class instance
352347
node.slow_start = slow_start.__get__(node)
353348
node.should_rm_dirs = True
349+
return node
350+
351+
def make_simple_node(
352+
self,
353+
base_dir=None,
354+
set_replication=False,
355+
ptrack_enable=False,
356+
initdb_params=[],
357+
pg_options={}):
358+
359+
node = self.make_empty_node(base_dir)
354360
node.init(
355361
initdb_params=initdb_params, allow_streaming=set_replication)
356362

@@ -1033,32 +1039,24 @@ def restore_node(
10331039

10341040
def catchup_node(
10351041
self,
1036-
backup_mode, source_pgdata, destination_base_dir,
1037-
options = [],
1038-
node = None
1042+
backup_mode, source_pgdata, destination_node,
1043+
options = []
10391044
):
10401045

1041-
real_destination_dir = os.path.join(self.tmp_path, destination_base_dir)
1042-
if not node:
1043-
shutil.rmtree(real_destination_dir, ignore_errors = True)
1044-
node = testgres.get_new_node('test', base_dir = real_destination_dir)
1045-
node.slow_start = slow_start.__get__(node)
1046-
node.should_rm_dirs = True
1047-
10481046
cmd_list = [
10491047
'catchup',
10501048
'--backup-mode={0}'.format(backup_mode),
10511049
'--catchup-source-pgdata={0}'.format(source_pgdata),
1052-
'--catchup-destination-pgdata={0}'.format(node.data_dir)
1050+
'--catchup-destination-pgdata={0}'.format(destination_node.data_dir)
10531051
]
10541052

10551053
if self.remote:
10561054
cmd_list += ['--remote-proto=ssh', '--remote-host=localhost']
10571055

10581056
self.run_pb(cmd_list + options)
10591057

1060-
node.append_conf(port=node.port)
1061-
return node
1058+
destination_node.append_conf(port=destination_node.port)
1059+
return destination_node
10621060

10631061
def show_pb(
10641062
self, backup_dir, instance=None, backup_id=None,

0 commit comments

Comments
 (0)