Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23f7e11

Browse files
committed
tests: minor fixes
1 parent 1534590 commit 23f7e11

File tree

3 files changed

+178
-41
lines changed

3 files changed

+178
-41
lines changed

tests/helpers/ptrack_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ def backup_node(
770770
self, backup_dir, instance, node, data_dir=False,
771771
backup_type='full', datname=False, options=[],
772772
asynchronous=False, gdb=False,
773-
old_binary=False, return_id=True
773+
old_binary=False, return_id=True, no_remote=False
774774
):
775775
if not node and not data_dir:
776776
print('You must provide ether node or data_dir for backup')
@@ -792,7 +792,7 @@ def backup_node(
792792
cmd_list += ['-D', data_dir]
793793

794794
# don`t forget to kill old_binary after remote ssh release
795-
if self.remote and not old_binary:
795+
if self.remote and not old_binary and not no_remote:
796796
options = options + [
797797
'--remote-proto=ssh',
798798
'--remote-host=localhost']

tests/retention.py

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,7 +2455,7 @@ def test_wal_depth_2(self):
24552455
output)
24562456

24572457
self.assertIn(
2458-
'VERBOSE: Archive backup {0} to stay consistent protect from '
2458+
'LOG: Archive backup {0} to stay consistent protect from '
24592459
'purge WAL interval between 0000000000000004 and 0000000000000004 '
24602460
'on timeline 1'.format(B1), output)
24612461

@@ -2465,12 +2465,12 @@ def test_wal_depth_2(self):
24652465
output)
24662466

24672467
self.assertIn(
2468-
'VERBOSE: Timeline 3 to stay reachable from timeline 1 protect '
2468+
'LOG: Timeline 3 to stay reachable from timeline 1 protect '
24692469
'from purge WAL interval between 0000000000000005 and '
24702470
'0000000000000008 on timeline 2', output)
24712471

24722472
self.assertIn(
2473-
'VERBOSE: Timeline 3 to stay reachable from timeline 1 protect '
2473+
'LOG: Timeline 3 to stay reachable from timeline 1 protect '
24742474
'from purge WAL interval between 0000000000000004 and '
24752475
'0000000000000005 on timeline 1', output)
24762476

@@ -2540,3 +2540,106 @@ def test_wal_depth_2(self):
25402540
self.validate_pb(backup_dir, 'node')
25412541

25422542
self.del_test_dir(module_name, fname)
2543+
2544+
def test_basic_wal_depth(self):
2545+
"""
2546+
B1---B1----B3-----B4----B5------> tli1
2547+
2548+
Expected result with wal-depth=1:
2549+
B1 B1 B3 B4 B5------> tli1
2550+
2551+
wal-depth=1
2552+
"""
2553+
fname = self.id().split('.')[3]
2554+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
2555+
node = self.make_simple_node(
2556+
base_dir=os.path.join(module_name, fname, 'node'),
2557+
set_replication=True,
2558+
initdb_params=['--data-checksums'])
2559+
2560+
self.init_pb(backup_dir)
2561+
self.add_instance(backup_dir, 'node', node)
2562+
self.set_config(backup_dir, 'node', options=['--archive-timeout=60s'])
2563+
self.set_archiving(backup_dir, 'node', node)
2564+
node.slow_start()
2565+
2566+
# FULL
2567+
node.pgbench_init(scale=1)
2568+
B1 = self.backup_node(backup_dir, 'node', node)
2569+
2570+
2571+
# B2
2572+
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
2573+
pgbench.wait()
2574+
B2 = self.backup_node(
2575+
backup_dir, 'node', node, backup_type='page')
2576+
2577+
# B3
2578+
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
2579+
pgbench.wait()
2580+
B3 = self.backup_node(
2581+
backup_dir, 'node', node, backup_type='page')
2582+
2583+
# B4
2584+
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
2585+
pgbench.wait()
2586+
B4 = self.backup_node(
2587+
backup_dir, 'node', node, backup_type='page')
2588+
2589+
# B5
2590+
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
2591+
pgbench.wait()
2592+
B5 = self.backup_node(
2593+
backup_dir, 'node', node, backup_type='page',
2594+
options=['--wal-depth=1', '--delete-wal'])
2595+
2596+
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
2597+
pgbench.wait()
2598+
2599+
target_xid = node.safe_psql(
2600+
"postgres",
2601+
"select txid_current()").rstrip()
2602+
2603+
self.switch_wal_segment(node)
2604+
2605+
pgbench = node.pgbench(options=['-T', '10', '-c', '2'])
2606+
pgbench.wait()
2607+
2608+
tli1 = self.show_archive(backup_dir, 'node', tli=1)
2609+
2610+
# check that there are 4 lost_segments intervals
2611+
self.assertEqual(len(tli1['lost-segments']), 4)
2612+
2613+
output = self.validate_pb(
2614+
backup_dir, 'node', B5,
2615+
options=['--recovery-target-xid={0}'.format(target_xid)])
2616+
2617+
print(output)
2618+
2619+
self.assertIn(
2620+
'INFO: Backup validation completed successfully on time',
2621+
output)
2622+
2623+
self.assertIn(
2624+
'xid {0} and LSN'.format(target_xid),
2625+
output)
2626+
2627+
for backup_id in [B1, B2, B3, B4]:
2628+
try:
2629+
self.validate_pb(
2630+
backup_dir, 'node', backup_id,
2631+
options=['--recovery-target-xid={0}'.format(target_xid)])
2632+
# we should die here because exception is what we expect to happen
2633+
self.assertEqual(
2634+
1, 0,
2635+
"Expecting Error because page backup should not be possible "
2636+
"without valid full backup.\n Output: {0} \n CMD: {1}".format(
2637+
repr(self.output), self.cmd))
2638+
except ProbackupException as e:
2639+
self.assertIn(
2640+
"ERROR: Not enough WAL records to xid {0}".format(target_xid),
2641+
e.message)
2642+
2643+
self.validate_pb(backup_dir, 'node')
2644+
2645+
self.del_test_dir(module_name, fname)

tests/show.py

Lines changed: 70 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,17 @@ def test_corrupt_correctness(self):
228228

229229
# FULL
230230
backup_local_id = self.backup_node(
231-
backup_dir, 'node', node, options=['--remote-proto=none'])
231+
backup_dir, 'node', node, no_remote=True)
232232

233233
output_local = self.show_pb(
234234
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
235235

236-
backup_remote_id = self.backup_node(
237-
backup_dir, 'node', node,
238-
options=['--remote-proto=ssh', '--remote-host=localhost'])
236+
if self.remote:
237+
backup_remote_id = self.backup_node(backup_dir, 'node', node)
238+
else:
239+
backup_remote_id = self.backup_node(
240+
backup_dir, 'node', node,
241+
options=['--remote-proto=ssh', '--remote-host=localhost'])
239242

240243
output_remote = self.show_pb(
241244
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
@@ -252,15 +255,19 @@ def test_corrupt_correctness(self):
252255
# DELTA
253256
backup_local_id = self.backup_node(
254257
backup_dir, 'node', node,
255-
backup_type='delta', options=['--remote-proto=none'])
258+
backup_type='delta', no_remote=True)
256259

257260
output_local = self.show_pb(
258261
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
259262
self.delete_pb(backup_dir, 'node', backup_local_id)
260263

261-
backup_remote_id = self.backup_node(
262-
backup_dir, 'node', node, backup_type='delta',
263-
options=['--remote-proto=ssh', '--remote-host=localhost'])
264+
if self.remote:
265+
backup_remote_id = self.backup_node(
266+
backup_dir, 'node', node, backup_type='delta')
267+
else:
268+
backup_remote_id = self.backup_node(
269+
backup_dir, 'node', node, backup_type='delta',
270+
options=['--remote-proto=ssh', '--remote-host=localhost'])
264271

265272
output_remote = self.show_pb(
266273
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
@@ -278,15 +285,19 @@ def test_corrupt_correctness(self):
278285
# PAGE
279286
backup_local_id = self.backup_node(
280287
backup_dir, 'node', node,
281-
backup_type='page', options=['--remote-proto=none'])
288+
backup_type='page', no_remote=True)
282289

283290
output_local = self.show_pb(
284291
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
285292
self.delete_pb(backup_dir, 'node', backup_local_id)
286293

287-
backup_remote_id = self.backup_node(
288-
backup_dir, 'node', node, backup_type='page',
289-
options=['--remote-proto=ssh', '--remote-host=localhost'])
294+
if self.remote:
295+
backup_remote_id = self.backup_node(
296+
backup_dir, 'node', node, backup_type='page')
297+
else:
298+
backup_remote_id = self.backup_node(
299+
backup_dir, 'node', node, backup_type='page',
300+
options=['--remote-proto=ssh', '--remote-host=localhost'])
290301

291302
output_remote = self.show_pb(
292303
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
@@ -324,14 +335,17 @@ def test_corrupt_correctness_1(self):
324335

325336
# FULL
326337
backup_local_id = self.backup_node(
327-
backup_dir, 'node', node, options=['--remote-proto=none'])
338+
backup_dir, 'node', node, no_remote=True)
328339

329340
output_local = self.show_pb(
330341
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
331342

332-
backup_remote_id = self.backup_node(
333-
backup_dir, 'node', node,
334-
options=['--remote-proto=ssh', '--remote-host=localhost'])
343+
if self.remote:
344+
backup_remote_id = self.backup_node(backup_dir, 'node', node)
345+
else:
346+
backup_remote_id = self.backup_node(
347+
backup_dir, 'node', node,
348+
options=['--remote-proto=ssh', '--remote-host=localhost'])
335349

336350
output_remote = self.show_pb(
337351
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
@@ -352,15 +366,19 @@ def test_corrupt_correctness_1(self):
352366
# DELTA
353367
backup_local_id = self.backup_node(
354368
backup_dir, 'node', node,
355-
backup_type='delta', options=['--remote-proto=none'])
369+
backup_type='delta', no_remote=True)
356370

357371
output_local = self.show_pb(
358372
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
359373
self.delete_pb(backup_dir, 'node', backup_local_id)
360374

361-
backup_remote_id = self.backup_node(
362-
backup_dir, 'node', node, backup_type='delta',
363-
options=['--remote-proto=ssh', '--remote-host=localhost'])
375+
if self.remote:
376+
backup_remote_id = self.backup_node(
377+
backup_dir, 'node', node, backup_type='delta')
378+
else:
379+
backup_remote_id = self.backup_node(
380+
backup_dir, 'node', node, backup_type='delta',
381+
options=['--remote-proto=ssh', '--remote-host=localhost'])
364382

365383
output_remote = self.show_pb(
366384
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
@@ -378,15 +396,19 @@ def test_corrupt_correctness_1(self):
378396
# PAGE
379397
backup_local_id = self.backup_node(
380398
backup_dir, 'node', node,
381-
backup_type='page', options=['--remote-proto=none'])
399+
backup_type='page', no_remote=True)
382400

383401
output_local = self.show_pb(
384402
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
385403
self.delete_pb(backup_dir, 'node', backup_local_id)
386404

387-
backup_remote_id = self.backup_node(
388-
backup_dir, 'node', node, backup_type='page',
389-
options=['--remote-proto=ssh', '--remote-host=localhost'])
405+
if self.remote:
406+
backup_remote_id = self.backup_node(
407+
backup_dir, 'node', node, backup_type='page')
408+
else:
409+
backup_remote_id = self.backup_node(
410+
backup_dir, 'node', node, backup_type='page',
411+
options=['--remote-proto=ssh', '--remote-host=localhost'])
390412

391413
output_remote = self.show_pb(
392414
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
@@ -425,14 +447,18 @@ def test_corrupt_correctness_2(self):
425447
# FULL
426448
backup_local_id = self.backup_node(
427449
backup_dir, 'node', node,
428-
options=['--remote-proto=none', '--compress'])
450+
options=['--compress'], no_remote=True)
429451

430452
output_local = self.show_pb(
431453
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
432454

433-
backup_remote_id = self.backup_node(
434-
backup_dir, 'node', node,
435-
options=['--remote-proto=ssh', '--remote-host=localhost', '--compress'])
455+
if self.remote:
456+
backup_remote_id = self.backup_node(
457+
backup_dir, 'node', node, options=['--compress'])
458+
else:
459+
backup_remote_id = self.backup_node(
460+
backup_dir, 'node', node,
461+
options=['--remote-proto=ssh', '--remote-host=localhost', '--compress'])
436462

437463
output_remote = self.show_pb(
438464
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
@@ -453,15 +479,19 @@ def test_corrupt_correctness_2(self):
453479
# DELTA
454480
backup_local_id = self.backup_node(
455481
backup_dir, 'node', node,
456-
backup_type='delta', options=['--remote-proto=none', '--compress'])
482+
backup_type='delta', options=['--compress'], no_remote=True)
457483

458484
output_local = self.show_pb(
459485
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
460486
self.delete_pb(backup_dir, 'node', backup_local_id)
461487

462-
backup_remote_id = self.backup_node(
463-
backup_dir, 'node', node, backup_type='delta',
464-
options=['--remote-proto=ssh', '--remote-host=localhost', '--compress'])
488+
if self.remote:
489+
backup_remote_id = self.backup_node(
490+
backup_dir, 'node', node, backup_type='delta', options=['--compress'])
491+
else:
492+
backup_remote_id = self.backup_node(
493+
backup_dir, 'node', node, backup_type='delta',
494+
options=['--remote-proto=ssh', '--remote-host=localhost', '--compress'])
465495

466496
output_remote = self.show_pb(
467497
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)
@@ -479,15 +509,19 @@ def test_corrupt_correctness_2(self):
479509
# PAGE
480510
backup_local_id = self.backup_node(
481511
backup_dir, 'node', node,
482-
backup_type='page', options=['--remote-proto=none', '--compress'])
512+
backup_type='page', options=['--compress'], no_remote=True)
483513

484514
output_local = self.show_pb(
485515
backup_dir, 'node', as_json=False, backup_id=backup_local_id)
486516
self.delete_pb(backup_dir, 'node', backup_local_id)
487517

488-
backup_remote_id = self.backup_node(
489-
backup_dir, 'node', node, backup_type='page',
490-
options=['--remote-proto=ssh', '--remote-host=localhost', '--compress'])
518+
if self.remote:
519+
backup_remote_id = self.backup_node(
520+
backup_dir, 'node', node, backup_type='page', options=['--compress'])
521+
else:
522+
backup_remote_id = self.backup_node(
523+
backup_dir, 'node', node, backup_type='page',
524+
options=['--remote-proto=ssh', '--remote-host=localhost', '--compress'])
491525

492526
output_remote = self.show_pb(
493527
backup_dir, 'node', as_json=False, backup_id=backup_remote_id)

0 commit comments

Comments
 (0)