1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-03-30 23:04:31 +02:00

tests: fix validate tests broken by PR #33

This commit is contained in:
Grigory Smolkin 2018-10-11 16:26:23 +03:00
parent cf88637be3
commit 0ff7d613d8

View File

@ -12,6 +12,57 @@ module_name = 'validate'
class ValidateTest(ProbackupTest, unittest.TestCase):
# @unittest.skip("skip")
# @unittest.expectedFailure
def test_validate_nullified_heap_page_backup(self):
"""
make node with nullified heap block
"""
fname = self.id().split('.')[3]
node = self.make_simple_node(
base_dir="{0}/{1}/node".format(module_name, fname),
initdb_params=['--data-checksums'],
pg_options={'wal_level': 'replica'}
)
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
self.set_archiving(backup_dir, 'node', node)
node.slow_start()
node.pgbench_init(scale=3)
file_path = node.safe_psql(
"postgres",
"select pg_relation_filepath('pgbench_accounts')").rstrip()
node.safe_psql(
"postgres",
"CHECKPOINT")
# Nullify some block in PostgreSQL
file = os.path.join(node.data_dir, file_path)
with open(file, 'r+b') as f:
f.seek(8192)
f.write(b"\x00"*8192)
f.flush()
f.close
self.backup_node(
backup_dir, 'node', node, options=["--log-level-file=verbose"])
log_file_path = os.path.join(backup_dir, "log", "pg_probackup.log")
with open(log_file_path) as f:
self.assertTrue(
'LOG: File: {0} blknum 1, empty page'.format(file) in f.read(),
'Failed to detect nullified block')
self.validate_pb(backup_dir)
# Clean after yourself
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
# @unittest.expectedFailure
def test_validate_wal_unreal_values(self):
@ -29,7 +80,7 @@ class ValidateTest(ProbackupTest, unittest.TestCase):
self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
self.set_archiving(backup_dir, 'node', node)
node.start()
node.slow_start()
node.pgbench_init(scale=3)
with node.connect("postgres") as con:
@ -198,7 +249,7 @@ class ValidateTest(ProbackupTest, unittest.TestCase):
# Corrupt some file
file = os.path.join(
backup_dir, 'backups/node', backup_id_2, 'database', file_path)
with open(file, "rb+", 0) as f:
with open(file, "r+b", 0) as f:
f.seek(42)
f.write(b"blah")
f.flush()
@ -219,6 +270,8 @@ class ValidateTest(ProbackupTest, unittest.TestCase):
'INFO: Validating parents for backup {0}'.format(
backup_id_2) in e.message and
'ERROR: Backup {0} is corrupt'.format(
backup_id_2) in e.message and
'WARNING: Backup {0} data files are corrupted'.format(
backup_id_2) in e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(e.message), self.cmd))
@ -1530,7 +1583,10 @@ class ValidateTest(ProbackupTest, unittest.TestCase):
base_dir="{0}/{1}/node".format(module_name, fname),
set_replication=True,
initdb_params=['--data-checksums'],
pg_options={'wal_level': 'replica', 'max_wal_senders': '2'}
pg_options={
'wal_level': 'replica',
'max_wal_senders': '2',
'checkpoint_timeout': '30'}
)
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
self.init_pb(backup_dir)
@ -1561,6 +1617,7 @@ class ValidateTest(ProbackupTest, unittest.TestCase):
self.output, self.cmd))
except ProbackupException as e:
pass
self.assertTrue(
self.show_pb(backup_dir, 'node')[6]['status'] == 'ERROR')
self.set_archiving(backup_dir, 'node', node)
@ -1709,11 +1766,12 @@ class ValidateTest(ProbackupTest, unittest.TestCase):
self.assertTrue(self.show_pb(backup_dir, 'node')[0]['status'] == 'OK')
os.rename(file_new, file)
file = os.path.join(
backup_dir, 'backups', 'node',
backup_id_page, 'database', 'postgresql.auto.conf')
backup_id_page, 'database', 'backup_label')
file_new = os.path.join(backup_dir, 'postgresql.auto.conf')
file_new = os.path.join(backup_dir, 'backup_label')
os.rename(file, file_new)
try:
@ -1785,9 +1843,9 @@ class ValidateTest(ProbackupTest, unittest.TestCase):
file = os.path.join(
backup_dir, 'backups', 'node',
corrupt_id, 'database', 'postgresql.auto.conf')
corrupt_id, 'database', 'backup_label')
file_new = os.path.join(backup_dir, 'postgresql.auto.conf')
file_new = os.path.join(backup_dir, 'backup_label')
os.rename(file, file_new)
try: