Skip to content

Commit 0ff7d61

Browse files
committed
tests: fix validate tests broken by PR #33
1 parent cf88637 commit 0ff7d61

File tree

1 file changed

+65
-7
lines changed

1 file changed

+65
-7
lines changed

tests/validate_test.py

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,57 @@
1212

1313
class ValidateTest(ProbackupTest, unittest.TestCase):
1414

15+
# @unittest.skip("skip")
16+
# @unittest.expectedFailure
17+
def test_validate_nullified_heap_page_backup(self):
18+
"""
19+
make node with nullified heap block
20+
"""
21+
fname = self.id().split('.')[3]
22+
node = self.make_simple_node(
23+
base_dir="{0}/{1}/node".format(module_name, fname),
24+
initdb_params=['--data-checksums'],
25+
pg_options={'wal_level': 'replica'}
26+
)
27+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
28+
self.init_pb(backup_dir)
29+
self.add_instance(backup_dir, 'node', node)
30+
self.set_archiving(backup_dir, 'node', node)
31+
node.slow_start()
32+
33+
node.pgbench_init(scale=3)
34+
35+
file_path = node.safe_psql(
36+
"postgres",
37+
"select pg_relation_filepath('pgbench_accounts')").rstrip()
38+
39+
node.safe_psql(
40+
"postgres",
41+
"CHECKPOINT")
42+
43+
# Nullify some block in PostgreSQL
44+
file = os.path.join(node.data_dir, file_path)
45+
with open(file, 'r+b') as f:
46+
f.seek(8192)
47+
f.write(b"\x00"*8192)
48+
f.flush()
49+
f.close
50+
51+
self.backup_node(
52+
backup_dir, 'node', node, options=["--log-level-file=verbose"])
53+
54+
log_file_path = os.path.join(backup_dir, "log", "pg_probackup.log")
55+
56+
with open(log_file_path) as f:
57+
self.assertTrue(
58+
'LOG: File: {0} blknum 1, empty page'.format(file) in f.read(),
59+
'Failed to detect nullified block')
60+
61+
self.validate_pb(backup_dir)
62+
63+
# Clean after yourself
64+
self.del_test_dir(module_name, fname)
65+
1566
# @unittest.skip("skip")
1667
# @unittest.expectedFailure
1768
def test_validate_wal_unreal_values(self):
@@ -29,7 +80,7 @@ def test_validate_wal_unreal_values(self):
2980
self.init_pb(backup_dir)
3081
self.add_instance(backup_dir, 'node', node)
3182
self.set_archiving(backup_dir, 'node', node)
32-
node.start()
83+
node.slow_start()
3384

3485
node.pgbench_init(scale=3)
3586
with node.connect("postgres") as con:
@@ -198,7 +249,7 @@ def test_validate_corrupted_intermediate_backup(self):
198249
# Corrupt some file
199250
file = os.path.join(
200251
backup_dir, 'backups/node', backup_id_2, 'database', file_path)
201-
with open(file, "rb+", 0) as f:
252+
with open(file, "r+b", 0) as f:
202253
f.seek(42)
203254
f.write(b"blah")
204255
f.flush()
@@ -219,6 +270,8 @@ def test_validate_corrupted_intermediate_backup(self):
219270
'INFO: Validating parents for backup {0}'.format(
220271
backup_id_2) in e.message and
221272
'ERROR: Backup {0} is corrupt'.format(
273+
backup_id_2) in e.message and
274+
'WARNING: Backup {0} data files are corrupted'.format(
222275
backup_id_2) in e.message,
223276
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
224277
repr(e.message), self.cmd))
@@ -1530,7 +1583,10 @@ def test_validate_corrupted_full(self):
15301583
base_dir="{0}/{1}/node".format(module_name, fname),
15311584
set_replication=True,
15321585
initdb_params=['--data-checksums'],
1533-
pg_options={'wal_level': 'replica', 'max_wal_senders': '2'}
1586+
pg_options={
1587+
'wal_level': 'replica',
1588+
'max_wal_senders': '2',
1589+
'checkpoint_timeout': '30'}
15341590
)
15351591
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
15361592
self.init_pb(backup_dir)
@@ -1561,6 +1617,7 @@ def test_validate_corrupted_full(self):
15611617
self.output, self.cmd))
15621618
except ProbackupException as e:
15631619
pass
1620+
15641621
self.assertTrue(
15651622
self.show_pb(backup_dir, 'node')[6]['status'] == 'ERROR')
15661623
self.set_archiving(backup_dir, 'node', node)
@@ -1709,11 +1766,12 @@ def test_validate_corrupted_full_1(self):
17091766
self.assertTrue(self.show_pb(backup_dir, 'node')[0]['status'] == 'OK')
17101767

17111768
os.rename(file_new, file)
1769+
17121770
file = os.path.join(
17131771
backup_dir, 'backups', 'node',
1714-
backup_id_page, 'database', 'postgresql.auto.conf')
1772+
backup_id_page, 'database', 'backup_label')
17151773

1716-
file_new = os.path.join(backup_dir, 'postgresql.auto.conf')
1774+
file_new = os.path.join(backup_dir, 'backup_label')
17171775
os.rename(file, file_new)
17181776

17191777
try:
@@ -1785,9 +1843,9 @@ def test_validate_corrupted_full_2(self):
17851843

17861844
file = os.path.join(
17871845
backup_dir, 'backups', 'node',
1788-
corrupt_id, 'database', 'postgresql.auto.conf')
1846+
corrupt_id, 'database', 'backup_label')
17891847

1790-
file_new = os.path.join(backup_dir, 'postgresql.auto.conf')
1848+
file_new = os.path.join(backup_dir, 'backup_label')
17911849
os.rename(file, file_new)
17921850

17931851
try:

0 commit comments

Comments
 (0)