From 6062362519522c78c273a94dcb8c0f52610e90dc Mon Sep 17 00:00:00 2001 From: Grigory Smolkin Date: Fri, 4 Oct 2019 10:36:56 +0300 Subject: [PATCH] tests: fixes --- tests/delete.py | 1 - tests/helpers/ptrack_helpers.py | 20 ++++++++++++++++- tests/retention.py | 40 ++++++++++++++++----------------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/tests/delete.py b/tests/delete.py index ce6bbb98..6df8269b 100644 --- a/tests/delete.py +++ b/tests/delete.py @@ -411,7 +411,6 @@ class DeleteTest(ProbackupTest, unittest.TestCase): node.slow_start() # Take FULL BACKUPs - backup_id_a = self.backup_node(backup_dir, 'node', node) backup_id_b = self.backup_node(backup_dir, 'node', node) diff --git a/tests/helpers/ptrack_helpers.py b/tests/helpers/ptrack_helpers.py index e8e27b8f..0f9cb097 100644 --- a/tests/helpers/ptrack_helpers.py +++ b/tests/helpers/ptrack_helpers.py @@ -949,7 +949,8 @@ class ProbackupTest(object): def show_archive( self, backup_dir, instance=None, options=[], - as_text=False, as_json=True, old_binary=False + as_text=False, as_json=True, old_binary=False, + tli=0 ): cmd_list = [ @@ -973,6 +974,23 @@ class ProbackupTest(object): data = self.run_pb(cmd_list + options, old_binary=old_binary) else: data = json.loads(self.run_pb(cmd_list + options, old_binary=old_binary)) + + if instance: + instance_timelines = None + for instance_name in data: + if instance_name['instance'] == instance: + instance_timelines = instance_name['timelines'] + break + + if tli > 0: + timeline_data = None + for timeline in instance_timelines: + if timeline['tli'] == tli: + return timeline + + if instance_timelines: + return instance_timelines + return data else: show_splitted = self.run_pb( diff --git a/tests/retention.py b/tests/retention.py index 11e4e033..0447e062 100644 --- a/tests/retention.py +++ b/tests/retention.py @@ -25,10 +25,8 @@ class RetentionTest(ProbackupTest, unittest.TestCase): self.set_archiving(backup_dir, 'node', node) node.slow_start() - with open(os.path.join( - backup_dir, 'backups', 'node', - "pg_probackup.conf"), "a") as conf: - conf.write("retention-redundancy = 1\n") + self.set_config( + backup_dir, 'node', options=['--retention-redundancy=1']) # Make backups to be purged self.backup_node(backup_dir, 'node', node) @@ -39,31 +37,31 @@ class RetentionTest(ProbackupTest, unittest.TestCase): self.assertEqual(len(self.show_pb(backup_dir, 'node')), 4) + output_before = self.show_archive(backup_dir, 'node', tli=1) + # Purge backups log = self.delete_expired( backup_dir, 'node', options=['--expired', '--wal']) self.assertEqual(len(self.show_pb(backup_dir, 'node')), 2) + output_after = self.show_archive(backup_dir, 'node', tli=1) + + self.assertEqual( + output_before['max-segno'], + output_after['max-segno']) + + self.assertNotEqual( + output_before['min-segno'], + output_after['min-segno']) + # Check that WAL segments were deleted - min_wal = None - max_wal = None - for line in log.splitlines(): - if line.startswith("INFO: removed min WAL segment"): - min_wal = line[31:-1] - elif line.startswith("INFO: removed max WAL segment"): - max_wal = line[31:-1] - - if not min_wal: - self.assertTrue(False, "min_wal is empty") - - if not max_wal: - self.assertTrue(False, "max_wal is not set") + min_wal = output_after['min-segno'] + max_wal = output_after['max-segno'] for wal_name in os.listdir(os.path.join(backup_dir, 'wal', 'node')): if not wal_name.endswith(".backup"): - # wal_name_b = wal_name.encode('ascii') - self.assertEqual(wal_name[8:] > min_wal[8:], True) - self.assertEqual(wal_name[8:] > max_wal[8:], True) + self.assertTrue(wal_name[8:] >= min_wal) + self.assertTrue(wal_name[8:] <= max_wal) # Clean after yourself self.del_test_dir(module_name, fname) @@ -1353,7 +1351,7 @@ class RetentionTest(ProbackupTest, unittest.TestCase): gdb.set_breakpoint('pg_stop_backup') gdb.run_until_break() - gdb._execute('signal SIGTERM') + gdb._execute('signal SIGKILL') gdb.continue_execution_until_error() page_id = self.show_pb(backup_dir, 'node')[1]['id']