Skip to content

Commit b67c0b5

Browse files
committed
add replica flag in slow_start() method
1 parent 2a1181e commit b67c0b5

File tree

3 files changed

+41
-39
lines changed

3 files changed

+41
-39
lines changed

tests/archive.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_pgpro434_1(self):
2929
self.init_pb(backup_dir)
3030
self.add_instance(backup_dir, 'node', node)
3131
self.set_archiving(backup_dir, 'node', node)
32-
node.start()
32+
node.slow_start()
3333

3434
node.safe_psql(
3535
"postgres",
@@ -89,7 +89,7 @@ def test_pgpro434_2(self):
8989
self.init_pb(backup_dir)
9090
self.add_instance(backup_dir, 'node', node)
9191
self.set_archiving(backup_dir, 'node', node)
92-
node.start()
92+
node.slow_start()
9393

9494
# FIRST TIMELINE
9595
node.safe_psql(
@@ -247,7 +247,7 @@ def test_pgpro434_3(self):
247247
node.append_conf(
248248
'postgresql.auto.conf', "archive_command = '{0} %p %f'".format(
249249
archive_script_path))
250-
node.start()
250+
node.slow_start()
251251
try:
252252
self.backup_node(
253253
backup_dir, 'node', node,
@@ -308,7 +308,7 @@ def test_arhive_push_file_exists(self):
308308
f.flush()
309309
f.close()
310310

311-
node.start()
311+
node.slow_start()
312312
node.safe_psql(
313313
"postgres",
314314
"create table t_heap as select i as id, md5(i::text) as text, "
@@ -368,7 +368,7 @@ def test_arhive_push_file_exists_overwrite(self):
368368
f.flush()
369369
f.close()
370370

371-
node.start()
371+
node.slow_start()
372372
node.safe_psql(
373373
"postgres",
374374
"create table t_heap as select i as id, md5(i::text) as text, "
@@ -423,7 +423,7 @@ def test_replica_archive(self):
423423
self.init_pb(backup_dir)
424424
# ADD INSTANCE 'MASTER'
425425
self.add_instance(backup_dir, 'master', master)
426-
master.start()
426+
master.slow_start()
427427

428428
replica = self.make_simple_node(
429429
base_dir="{0}/{1}/replica".format(module_name, fname))
@@ -444,7 +444,7 @@ def test_replica_archive(self):
444444

445445
self.add_instance(backup_dir, 'replica', replica)
446446
self.set_archiving(backup_dir, 'replica', replica, replica=True)
447-
replica.start()
447+
replica.slow_start(replica=True)
448448

449449
# Check data correctness on replica
450450
after = replica.safe_psql("postgres", "SELECT * FROM t_heap")
@@ -481,7 +481,7 @@ def test_replica_archive(self):
481481
self.restore_node(backup_dir, 'replica', data_dir=node.data_dir)
482482
node.append_conf(
483483
'postgresql.auto.conf', 'port = {0}'.format(node.port))
484-
node.start()
484+
node.slow_start()
485485
# CHECK DATA CORRECTNESS
486486
after = node.safe_psql("postgres", "SELECT * FROM t_heap")
487487
self.assertEqual(before, after)
@@ -513,7 +513,7 @@ def test_replica_archive(self):
513513
backup_dir, 'replica', data_dir=node.data_dir, backup_id=backup_id)
514514
node.append_conf(
515515
'postgresql.auto.conf', 'port = {0}'.format(node.port))
516-
node.start()
516+
node.slow_start()
517517
# CHECK DATA CORRECTNESS
518518
after = node.safe_psql("postgres", "SELECT * FROM t_heap")
519519
self.assertEqual(before, after)
@@ -547,7 +547,7 @@ def test_master_and_replica_parallel_archiving(self):
547547
# ADD INSTANCE 'MASTER'
548548
self.add_instance(backup_dir, 'master', master)
549549
self.set_archiving(backup_dir, 'master', master)
550-
master.start()
550+
master.slow_start()
551551

552552
master.psql(
553553
"postgres",
@@ -573,7 +573,7 @@ def test_master_and_replica_parallel_archiving(self):
573573
self.add_instance(backup_dir, 'replica', replica)
574574
# SET ARCHIVING FOR REPLICA
575575
self.set_archiving(backup_dir, 'replica', replica, replica=True)
576-
replica.start()
576+
replica.slow_start(replica=True)
577577

578578
# CHECK LOGICAL CORRECTNESS on REPLICA
579579
after = replica.safe_psql("postgres", "SELECT * FROM t_heap")
@@ -628,7 +628,7 @@ def test_master_and_replica_concurrent_archiving(self):
628628
# ADD INSTANCE 'MASTER'
629629
self.add_instance(backup_dir, 'master', master)
630630
self.set_archiving(backup_dir, 'master', master)
631-
master.start()
631+
master.slow_start()
632632

633633
master.psql(
634634
"postgres",
@@ -655,7 +655,7 @@ def test_master_and_replica_concurrent_archiving(self):
655655
# self.add_instance(backup_dir, 'replica', replica)
656656
# SET ARCHIVING FOR REPLICA
657657
# self.set_archiving(backup_dir, 'replica', replica, replica=True)
658-
replica.start()
658+
replica.slow_start(replica=True)
659659

660660
# CHECK LOGICAL CORRECTNESS on REPLICA
661661
after = replica.safe_psql("postgres", "SELECT * FROM t_heap")

tests/helpers/ptrack_helpers.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __str__(self):
112112
return '\n ERROR: {0}\n CMD: {1}'.format(repr(self.message), self.cmd)
113113

114114

115-
def slow_start(self):
115+
def slow_start(self, replica=False):
116116

117117
# wait for https://github.com/postgrespro/testgres/pull/50
118118
# self.poll_query_until(
@@ -121,14 +121,24 @@ def slow_start(self):
121121
# raise_operational_error=False)
122122

123123
self.start()
124-
while True:
125-
try:
126-
self.poll_query_until(
127-
"postgres",
128-
"SELECT not pg_is_in_recovery()")
129-
break
130-
except Exception as e:
131-
continue
124+
if not replica:
125+
while True:
126+
try:
127+
self.poll_query_until(
128+
"postgres",
129+
"SELECT not pg_is_in_recovery()")
130+
break
131+
except Exception as e:
132+
continue
133+
else:
134+
while True:
135+
try:
136+
self.poll_query_until(
137+
"postgres",
138+
"SELECT pg_is_in_recovery()")
139+
break
140+
except Exception as e:
141+
continue
132142

133143

134144
class ProbackupTest(object):

tests/replica.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_replica_stream_ptrack_backup(self):
5050
self.set_replica(master, replica)
5151

5252
# Check data correctness on replica
53-
replica.start(["-t", "600"])
53+
replica.slow_start(replica=True)
5454
after = replica.safe_psql("postgres", "SELECT * FROM t_heap")
5555
self.assertEqual(before, after)
5656

@@ -82,7 +82,7 @@ def test_replica_stream_ptrack_backup(self):
8282
self.restore_node(backup_dir, 'replica', data_dir=node.data_dir)
8383
node.append_conf(
8484
'postgresql.auto.conf', 'port = {0}'.format(node.port))
85-
node.start()
85+
node.slow_start()
8686
# CHECK DATA CORRECTNESS
8787
after = node.safe_psql("postgres", "SELECT * FROM t_heap")
8888
self.assertEqual(before, after)
@@ -113,7 +113,7 @@ def test_replica_stream_ptrack_backup(self):
113113
backup_dir, 'replica', data_dir=node.data_dir, backup_id=backup_id)
114114
node.append_conf(
115115
'postgresql.auto.conf', 'port = {0}'.format(node.port))
116-
node.start()
116+
node.slow_start()
117117
# CHECK DATA CORRECTNESS
118118
after = node.safe_psql("postgres", "SELECT * FROM t_heap")
119119
self.assertEqual(before, after)
@@ -143,7 +143,7 @@ def test_replica_archive_page_backup(self):
143143
self.set_archiving(backup_dir, 'master', master)
144144
# force more frequent wal switch
145145
master.append_conf('postgresql.auto.conf', 'archive_timeout = 10')
146-
master.start()
146+
master.slow_start()
147147

148148
replica = self.make_simple_node(
149149
base_dir="{0}/{1}/replica".format(module_name, fname))
@@ -166,7 +166,7 @@ def test_replica_archive_page_backup(self):
166166
# Settings for Replica
167167
self.set_replica(master, replica)
168168
self.set_archiving(backup_dir, 'replica', replica, replica=True)
169-
replica.start(["-t", "600"])
169+
replica.slow_start(replica=True)
170170

171171
# Check data correctness on replica
172172
after = replica.safe_psql("postgres", "SELECT * FROM t_heap")
@@ -200,7 +200,7 @@ def test_replica_archive_page_backup(self):
200200
self.restore_node(backup_dir, 'replica', data_dir=node.data_dir)
201201
node.append_conf(
202202
'postgresql.auto.conf', 'port = {0}'.format(node.port))
203-
node.start()
203+
node.slow_start()
204204
# CHECK DATA CORRECTNESS
205205
after = node.safe_psql("postgres", "SELECT * FROM t_heap")
206206
self.assertEqual(before, after)
@@ -231,7 +231,7 @@ def test_replica_archive_page_backup(self):
231231
backup_dir, 'replica', data_dir=node.data_dir, backup_id=backup_id)
232232
node.append_conf(
233233
'postgresql.auto.conf', 'port = {0}'.format(node.port))
234-
node.start()
234+
node.slow_start()
235235
# CHECK DATA CORRECTNESS
236236
after = node.safe_psql("postgres", "SELECT * FROM t_heap")
237237
self.assertEqual(before, after)
@@ -260,7 +260,7 @@ def test_make_replica_via_restore(self):
260260
self.set_archiving(backup_dir, 'master', master)
261261
# force more frequent wal switch
262262
master.append_conf('postgresql.auto.conf', 'archive_timeout = 10')
263-
master.start()
263+
master.slow_start()
264264

265265
replica = self.make_simple_node(
266266
base_dir="{0}/{1}/replica".format(module_name, fname))
@@ -287,15 +287,7 @@ def test_make_replica_via_restore(self):
287287
self.set_archiving(backup_dir, 'replica', replica, replica=True)
288288
replica.append_conf(
289289
'postgresql.auto.conf', 'port = {0}'.format(replica.port))
290-
replica.start(["-t", "600"])
291-
292-
time.sleep(1)
293-
self.assertEqual(
294-
master.safe_psql(
295-
"postgres",
296-
"select exists(select * from pg_stat_replication)"
297-
).rstrip(),
298-
't')
290+
replica.slow_start(replica=True)
299291

300292
# Clean after yourself
301293
self.del_test_dir(module_name, fname)

0 commit comments

Comments
 (0)