Skip to content

Commit 38407a0

Browse files
author
Artur Zakirov
committed
Fix validation test
1 parent c2410fc commit 38407a0

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

tests/pb_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def show_pb(self, node, id=None, options=[], as_text=False):
178178
if line[0] != six.b("#")[0]
179179
])
180180

181-
def validate_pb(self, node, id, options=[]):
181+
def validate_pb(self, node, id=None, options=[]):
182182
cmd_list = [
183183
"-B", self.backup_dir(node),
184184
"validate",

tests/validate_test.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from os import path, listdir
33
import six
44
from .pb_lib import ProbackupTest
5+
from datetime import datetime, timedelta
56
from testgres import stop_all
67
import subprocess
78

@@ -18,9 +19,9 @@ def tearDownClass(cls):
1819
except:
1920
pass
2021

21-
def test_validate_broke_wal_1(self):
22+
def test_validate_wal_1(self):
2223
"""recovery to latest from full backup"""
23-
node = self.make_bnode('test_validate_broke_wal_1', base_dir="tmp_dirs/validate/broke_wal_1")
24+
node = self.make_bnode('test_validate_wal_1', base_dir="tmp_dirs/validate/wal_1")
2425
node.start()
2526
self.assertEqual(self.init_pb(node), six.b(""))
2627
node.pgbench_init(scale=2)
@@ -40,6 +41,9 @@ def test_validate_broke_wal_1(self):
4041
pgbench.wait()
4142
pgbench.stdout.close()
4243

44+
# Save time to validate
45+
target_time = datetime.now()
46+
4347
target_xid = None
4448
with node.connect("postgres") as con:
4549
res = con.execute("INSERT INTO tbl0005 VALUES ('inserted') RETURNING (xmin)")
@@ -49,13 +53,42 @@ def test_validate_broke_wal_1(self):
4953
node.execute("postgres", "SELECT pg_switch_xlog()")
5054
node.stop({"-m": "immediate"})
5155

56+
id_backup = self.show_pb(node)[0].id
57+
58+
# Validate to real time
59+
self.assertIn(six.b("INFO: Backup validation stopped on"),
60+
self.validate_pb(node, options=["--time='{:%Y-%m-%d %H:%M:%S}'".format(
61+
target_time)]))
62+
63+
# Validate to unreal time
64+
self.assertIn(six.b("ERROR: no full backup found, cannot validate."),
65+
self.validate_pb(node, options=["--time='{:%Y-%m-%d %H:%M:%S}'".format(
66+
target_time - timedelta(days=2))]))
67+
68+
# Validate to unreal time #2
69+
self.assertIn(six.b("ERROR: there are no WAL records to time"),
70+
self.validate_pb(node, options=["--time='{:%Y-%m-%d %H:%M:%S}'".format(
71+
target_time + timedelta(days=2))]))
72+
73+
# Validate to real xid
74+
self.assertIn(six.b("INFO: Backup validation stopped on"),
75+
self.validate_pb(node, options=["--xid=%s" % target_xid]))
76+
77+
# Validate to unreal xid
78+
self.assertIn(six.b("ERROR: there are no WAL records to xid"),
79+
self.validate_pb(node, options=["--xid=%d" % (int(target_xid) + 1000)]))
80+
81+
# Validate with backup ID
82+
self.assertIn(six.b("INFO: Backup validation stopped on"),
83+
self.validate_pb(node, id_backup))
84+
85+
# Validate broken WAL
5286
wals_dir = path.join(self.backup_dir(node), "wal")
5387
wals = [f for f in listdir(wals_dir) if path.isfile(path.join(wals_dir, f))]
5488
wals.sort()
5589
with open(path.join(wals_dir, wals[-3]), "rb+") as f:
5690
f.seek(256)
5791
f.write(six.b("blablabla"))
5892

59-
id_backup = self.show_pb(node)[0].id
6093
res = self.validate_pb(node, id_backup, options=['--xid=%s' % target_xid])
61-
self.assertIn(six.b("there are not WAL records to xid"), res)
94+
self.assertIn(six.b("there are no WAL records to xid"), res)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy