Skip to content

Commit 61b25eb

Browse files
committed
[Issue #174] tests refactoring
1 parent b16ea0e commit 61b25eb

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

tests/archive.py

+23-19
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,11 @@ def test_archive_push_file_exists(self):
398398
log_content)
399399

400400
self.assertIn(
401-
'INFO: pg_probackup archive-push from',
401+
'pg_probackup push file',
402402
log_content)
403403

404404
self.assertIn(
405-
'ERROR: WAL segment ',
406-
log_content)
407-
408-
self.assertIn(
409-
'already exists.',
405+
'WAL file already exists in archive with different checksum',
410406
log_content)
411407

412408
self.assertNotIn(
@@ -448,8 +444,7 @@ def test_archive_push_file_exists_overwrite(self):
448444
base_dir=os.path.join(module_name, fname, 'node'),
449445
set_replication=True,
450446
initdb_params=['--data-checksums'],
451-
pg_options={
452-
'checkpoint_timeout': '30s'})
447+
pg_options={'checkpoint_timeout': '30s'})
453448

454449
self.init_pb(backup_dir)
455450
self.add_instance(backup_dir, 'node', node)
@@ -487,24 +482,32 @@ def test_archive_push_file_exists_overwrite(self):
487482
self.assertIn(
488483
'DETAIL: The failed archive command was:', log_content)
489484
self.assertIn(
490-
'INFO: pg_probackup archive-push from', log_content)
485+
'pg_probackup push file', log_content)
486+
self.assertNotIn(
487+
'WAL file already exists in archive with '
488+
'different checksum, overwriting', log_content)
491489
self.assertIn(
492-
'{0}" already exists.'.format(filename), log_content)
490+
'WAL file already exists in archive with '
491+
'different checksum', log_content)
493492

494493
self.assertNotIn(
495494
'pg_probackup archive-push completed successfully', log_content)
496495

497496
self.set_archiving(backup_dir, 'node', node, overwrite=True)
498497
node.reload()
499498
self.switch_wal_segment(node)
500-
sleep(2)
499+
sleep(5)
501500

502501
with open(log_file, 'r') as f:
503502
log_content = f.read()
504503
self.assertTrue(
505504
'pg_probackup archive-push completed successfully' in log_content,
506505
'Expecting messages about successfull execution archive_command')
507506

507+
self.assertIn(
508+
'WAL file already exists in archive with '
509+
'different checksum, overwriting', log_content)
510+
508511
# Clean after yourself
509512
self.del_test_dir(module_name, fname)
510513

@@ -520,7 +523,7 @@ def test_archive_push_partial_file_exists(self):
520523

521524
self.init_pb(backup_dir)
522525
self.add_instance(backup_dir, 'node', node)
523-
self.set_archiving(backup_dir, 'node', node)
526+
self.set_archiving(backup_dir, 'node', node, log_level='verbose')
524527

525528
node.slow_start()
526529

@@ -579,12 +582,9 @@ def test_archive_push_partial_file_exists(self):
579582
log_file = os.path.join(node.logs_dir, 'postgresql.log')
580583
with open(log_file, 'r') as f:
581584
log_content = f.read()
582-
self.assertIn(
583-
'Cannot open destination temporary WAL file',
584-
log_content)
585585

586586
self.assertIn(
587-
'Reusing stale destination temporary WAL file',
587+
'Reusing stale temp WAL file',
588588
log_content)
589589

590590
# Clean after yourself
@@ -905,8 +905,8 @@ def test_basic_master_and_replica_concurrent_archiving(self):
905905
initdb_params=['--data-checksums'],
906906
pg_options={
907907
'checkpoint_timeout': '30s',
908-
'archive_timeout': '10s'}
909-
)
908+
'archive_timeout': '10s'})
909+
910910
replica = self.make_simple_node(
911911
base_dir=os.path.join(module_name, fname, 'replica'))
912912
replica.cleanup()
@@ -923,6 +923,8 @@ def test_basic_master_and_replica_concurrent_archiving(self):
923923
"md5(repeat(i::text,10))::tsvector as tsvector "
924924
"from generate_series(0,10000) i")
925925

926+
master.pgbench_init(scale=5)
927+
926928
# TAKE FULL ARCHIVE BACKUP FROM MASTER
927929
self.backup_node(backup_dir, 'master', master)
928930
# GET LOGICAL CONTENT FROM MASTER
@@ -1718,7 +1720,7 @@ def test_hexadecimal_timeline(self):
17181720

17191721
self.init_pb(backup_dir)
17201722
self.add_instance(backup_dir, 'node', node)
1721-
self.set_archiving(backup_dir, 'node', node)
1723+
self.set_archiving(backup_dir, 'node', node, log_level='verbose')
17221724
node.slow_start()
17231725

17241726
backup_id = self.backup_node(backup_dir, 'node', node)
@@ -1734,6 +1736,8 @@ def test_hexadecimal_timeline(self):
17341736
node.slow_start()
17351737
node.pgbench_init(scale=2)
17361738

1739+
sleep(5)
1740+
17371741
show = self.show_archive(backup_dir)
17381742

17391743
timelines = show[0]['timelines']

tests/helpers/ptrack_helpers.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,8 @@ def get_recovery_conf(self, node):
11311131

11321132
def set_archiving(
11331133
self, backup_dir, instance, node, replica=False,
1134-
overwrite=False, compress=False, old_binary=False):
1134+
overwrite=False, compress=False, old_binary=False,
1135+
log_level=False):
11351136

11361137
# parse postgresql.auto.conf
11371138
options = {}
@@ -1161,12 +1162,21 @@ def set_archiving(
11611162
if overwrite:
11621163
options['archive_command'] += '--overwrite '
11631164

1165+
options['archive_command'] += '--log-level-console=verbose '
1166+
options['archive_command'] += '-j 10 '
1167+
options['archive_command'] += '--no-sync '
1168+
11641169
if os.name == 'posix':
11651170
options['archive_command'] += '--wal-file-path=%p --wal-file-name=%f'
11661171

11671172
elif os.name == 'nt':
11681173
options['archive_command'] += '--wal-file-path="%p" --wal-file-name="%f"'
11691174

1175+
if log_level:
1176+
options['archive_command'] += ' --log-level-console={0}'.format(log_level)
1177+
options['archive_command'] += ' --log-level-file={0} '.format(log_level)
1178+
1179+
11701180
self.set_auto_conf(node, options)
11711181

11721182
def get_restore_command(self, backup_dir, instance, node):

0 commit comments

Comments
 (0)