Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d6a2d36

Browse files
committed
tests: minor fixes, new tests for ptrack
1 parent ecd6d11 commit d6a2d36

File tree

6 files changed

+494
-206
lines changed

6 files changed

+494
-206
lines changed

tests/backup_test.py

Lines changed: 92 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def test_incremental_backup_corrupt_full(self):
162162
except ProbackupException as e:
163163
self.assertTrue("INFO: Validate backups of the instance 'node'\n" in e.message
164164
and 'WARNING: Backup file "{0}" is not found\n'.format(file) in e.message
165-
and "WARNING: Backup {0} is corrupted\n".format(backup_id) in e.message
165+
and "WARNING: Backup {0} data files are corrupted\n".format(backup_id) in e.message
166166
and "INFO: Some backups are not valid\n" in e.message,
167167
"\n Unexpected Error Message: {0}\n CMD: {1}".format(repr(e.message), self.cmd))
168168

@@ -231,50 +231,125 @@ def test_ptrack_threads_stream(self):
231231
self.del_test_dir(module_name, fname)
232232

233233
# @unittest.skip("skip")
234-
def test_page_checksumm_fail(self):
234+
def test_checksumm_fail_heal_via_ptrack(self):
235235
"""make node, corrupt some page, check that backup failed"""
236236
fname = self.id().split('.')[3]
237-
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
237+
node = self.make_simple_node(
238+
base_dir="{0}/{1}/node".format(module_name, fname),
238239
set_replication=True,
239240
initdb_params=['--data-checksums'],
240241
pg_options={'wal_level': 'replica', 'max_wal_senders': '2'}
241242
)
242243
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
244+
243245
self.init_pb(backup_dir)
244246
self.add_instance(backup_dir, 'node', node)
245247
node.start()
246248

247-
self.backup_node(backup_dir, 'node', node, backup_type="full", options=["-j", "4", "--stream"])
249+
self.backup_node(
250+
backup_dir, 'node', node,
251+
backup_type="full", options=["-j", "4", "--stream"])
248252

249253
node.safe_psql(
250254
"postgres",
251-
"create table t_heap as select 1 as id, md5(i::text) as text, md5(repeat(i::text,10))::tsvector as tsvector from generate_series(0,1000) i")
255+
"create table t_heap as select 1 as id, md5(i::text) as text, "
256+
"md5(repeat(i::text,10))::tsvector as tsvector "
257+
"from generate_series(0,1000) i")
252258
node.safe_psql(
253259
"postgres",
254260
"CHECKPOINT;")
255261

256-
heap_path = node.safe_psql("postgres", "select pg_relation_filepath('t_heap')").rstrip()
262+
heap_path = node.safe_psql(
263+
"postgres",
264+
"select pg_relation_filepath('t_heap')").rstrip()
265+
266+
with open(os.path.join(node.data_dir, heap_path), "rb+", 0) as f:
267+
f.seek(9000)
268+
f.write(b"bla")
269+
f.flush()
270+
f.close
271+
272+
self.backup_node(
273+
backup_dir, 'node', node, backup_type="full",
274+
options=["-j", "4", "--stream", '--log-level-file=verbose'])
275+
276+
# open log file and check
277+
with open(os.path.join(backup_dir, 'log', 'pg_probackup.log')) as f:
278+
log_content = f.read()
279+
self.assertIn('block 1, try fetching via SQL', log_content)
280+
self.assertIn('SELECT pg_ptrack_get_block', log_content)
281+
f.close
282+
283+
self.assertTrue(
284+
self.show_pb(backup_dir, 'node')[1]['Status'] == 'OK',
285+
"Backup Status should be OK")
286+
287+
# Clean after yourself
288+
# self.del_test_dir(module_name, fname)
289+
290+
# @unittest.skip("skip")
291+
def test_checksumm_fail_heal_via_ptrack_fail(self):
292+
"""make node, corrupt some page, check that backup failed"""
293+
fname = self.id().split('.')[3]
294+
node = self.make_simple_node(
295+
base_dir="{0}/{1}/node".format(module_name, fname),
296+
set_replication=True,
297+
initdb_params=['--data-checksums'],
298+
pg_options={'wal_level': 'replica', 'max_wal_senders': '2'}
299+
)
300+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
301+
302+
self.init_pb(backup_dir)
303+
self.add_instance(backup_dir, 'node', node)
304+
node.start()
305+
306+
self.backup_node(
307+
backup_dir, 'node', node, backup_type="full",
308+
options=["-j", "4", "--stream"])
309+
310+
node.safe_psql(
311+
"postgres",
312+
"create table t_heap as select 1 as id, md5(i::text) as text, "
313+
"md5(repeat(i::text,10))::tsvector as tsvector "
314+
"from generate_series(0,1000) i")
315+
node.safe_psql(
316+
"postgres",
317+
"CHECKPOINT;")
318+
319+
heap_path = node.safe_psql(
320+
"postgres",
321+
"select pg_relation_filepath('t_heap')").rstrip()
257322
node.stop()
258323

259-
with open(os.path.join(node.data_dir,heap_path), "rb+", 0) as f:
324+
with open(os.path.join(node.data_dir, heap_path), "rb+", 0) as f:
260325
f.seek(9000)
261326
f.write(b"bla")
262327
f.flush()
263328
f.close
264329
node.start()
265330

266331
try:
267-
self.backup_node(backup_dir, 'node', node, backup_type="full", options=["-j", "4", "--stream"])
332+
self.backup_node(
333+
backup_dir, 'node', node,
334+
backup_type="full", options=["-j", "4", "--stream"])
268335
# we should die here because exception is what we expect to happen
269-
self.assertEqual(1, 0, "Expecting Error because of page corruption in PostgreSQL instance.\n Output: {0} \n CMD: {1}".format(
270-
repr(self.output), self.cmd))
336+
self.assertEqual(
337+
1, 0,
338+
"Expecting Error because of page "
339+
"corruption in PostgreSQL instance.\n"
340+
" Output: {0} \n CMD: {1}".format(
341+
repr(self.output), self.cmd))
271342
except ProbackupException as e:
272-
self.assertIn("ERROR: File", e.message,
273-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(repr(e.message), self.cmd))
274-
self.assertIn("blknum", e.message,
275-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(repr(e.message), self.cmd))
276-
self.assertIn("have wrong checksum", e.message,
277-
"\n Unexpected Error Message: {0}\n CMD: {1}".format(repr(e.message), self.cmd))
343+
self.assertTrue(
344+
"WARNING: File" in e.message and
345+
"blknum" in e.message and
346+
"have wrong checksum" in e.message,
347+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
348+
repr(e.message), self.cmd))
349+
350+
self.assertTrue(
351+
self.show_pb(backup_dir, 'node')[1]['Status'] == 'ERROR',
352+
"Backup Status should be ERROR")
278353

279354
# Clean after yourself
280-
self.del_test_dir(module_name, fname)
355+
# self.del_test_dir(module_name, fname)

tests/expected/option_help.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,15 @@ pg_probackup - utility to manage backup/recovery of PostgreSQL database.
5959
pg_probackup del-instance -B backup-dir
6060
--instance=instance_name
6161

62+
pg_probackup archive-push -B backup-dir --instance=instance_name
63+
--wal-file-path=wal-file-path
64+
--wal-file-name=wal-file-name
65+
[--compress [--compress-level=compress-level]]
66+
[--overwrite]
67+
68+
pg_probackup archive-get -B backup-dir --instance=instance_name
69+
--wal-file-path=wal-file-path
70+
--wal-file-name=wal-file-name
71+
6272
Read the website for details. <https://github.com/postgrespro/pg_probackup>
6373
Report bugs to <https://github.com/postgrespro/pg_probackup/issues>.

tests/helpers/ptrack_helpers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ def pgdata_content(self, directory):
858858
'postmaster.pid', 'postmaster.opts',
859859
'pg_internal.init', 'postgresql.auto.conf',
860860
'backup_label', 'tablespace_map', 'recovery.conf',
861-
'ptrack_control', 'ptrack_init'
861+
'ptrack_control', 'ptrack_init', 'pg_control'
862862
]
863863
suffixes_to_ignore = (
864864
'_ptrack'
@@ -1119,7 +1119,10 @@ def continue_execution_until_exit(self):
11191119
continue
11201120
if line.startswith('*stopped,reason="breakpoint-hit"'):
11211121
continue
1122-
if line.startswith('*stopped,reason="exited-normally"'):
1122+
if (
1123+
line.startswith('*stopped,reason="exited-normally"') or
1124+
line == '*stopped\n'
1125+
):
11231126
return
11241127
raise GdbException(
11251128
'Failed to continue execution until exit.\n'
@@ -1164,11 +1167,10 @@ def _execute(self, cmd, running=True):
11641167
self.proc.stdin.flush()
11651168

11661169
while True:
1167-
# sleep(1)
11681170
line = self.proc.stdout.readline()
11691171
output += [line]
11701172
if self.verbose:
1171-
print(line)
1173+
print(repr(line))
11721174
if line == '^done\n' or line.startswith('*stopped'):
11731175
break
11741176
if running and line.startswith('*running'):

tests/page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_page_vacuum_truncate(self):
9696
node_restored.start()
9797

9898
# Clean after yourself
99-
# self.del_test_dir(module_name, fname)
99+
self.del_test_dir(module_name, fname)
100100

101101
# @unittest.skip("skip")
102102
def test_page_stream(self):

0 commit comments

Comments
 (0)