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

Commit 68e2742

Browse files
committed
tests: major fixes
1 parent 45923cf commit 68e2742

File tree

5 files changed

+428
-134
lines changed

5 files changed

+428
-134
lines changed

tests/expected/option_help.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pg_probackup - utility to manage backup/recovery of PostgreSQL database.
2929
pg_probackup backup -B backup-path -b backup-mode --instance=instance_name
3030
[-C] [--stream [-S slot-name]] [--backup-pg-log]
3131
[-j num-threads] [--archive-timeout=archive-timeout]
32+
[--compress]
3233
[--compress-algorithm=compress-algorithm]
3334
[--compress-level=compress-level]
3435
[--progress] [--delete-expired]

tests/helpers/ptrack_helpers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,11 +815,14 @@ def get_username(self):
815815
""" Returns current user name """
816816
return pwd.getpwuid(os.getuid())[0]
817817

818+
def version_to_num(self, version):
819+
return testgres.version_to_num(version)
820+
818821
def switch_wal_segment(self, node):
819822
""" Execute pg_switch_wal/xlog() in given node"""
820-
if testgres.version_to_num(
823+
if self.version_to_num(
821824
node.safe_psql("postgres", "show server_version")
822-
) >= testgres.version_to_num('10.0'):
825+
) >= self.version_to_num('10.0'):
823826
node.safe_psql("postgres", "select pg_switch_wal()")
824827
else:
825828
node.safe_psql("postgres", "select pg_switch_xlog()")

tests/pgpro589.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def test_pgpro589(self):
1818
check that no files where copied to backup catalogue
1919
"""
2020
fname = self.id().split('.')[3]
21-
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
21+
node = self.make_simple_node(
22+
base_dir="{0}/{1}/node".format(module_name, fname),
2223
initdb_params=['--data-checksums'],
2324
pg_options={'wal_level': 'replica'}
2425
)
@@ -39,25 +40,41 @@ def test_pgpro589(self):
3940
)
4041
pgbench.wait()
4142
pgbench.stdout.close()
42-
path = node.safe_psql("postgres", "select pg_relation_filepath('pgbench_accounts')").rstrip().decode("utf-8")
43+
path = node.safe_psql(
44+
"postgres",
45+
"select pg_relation_filepath('pgbench_accounts')").rstrip().decode(
46+
"utf-8")
4347

4448
try:
45-
self.backup_node(backup_dir, 'node', node, options=['--archive-timeout=10'])
49+
self.backup_node(
50+
backup_dir, 'node', node,
51+
options=['--archive-timeout=10'])
4652
# we should die here because exception is what we expect to happen
47-
self.assertEqual(1, 0, "Expecting Error because of missing archive wal segment with start_lsn.\n Output: {0} \n CMD: {1}".format(
48-
repr(self.output), self.cmd))
53+
self.assertEqual(
54+
1, 0,
55+
"Expecting Error because of missing archive wal "
56+
"segment with start_lsn.\n Output: {0} \n CMD: {1}".format(
57+
repr(self.output), self.cmd))
4958
except ProbackupException as e:
5059
self.assertTrue(
51-
'INFO: wait for WAL segment' in e.message
52-
and 'ERROR: switched WAL segment' in e.message
53-
and 'could not be archived' in e.message,
54-
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
60+
'INFO: Wait for WAL segment' in e.message and
61+
'ERROR: Switched WAL segment' in e.message and
62+
'could not be archived' in e.message,
63+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
64+
repr(e.message), self.cmd))
5565

5666
backup_id = self.show_pb(backup_dir, 'node')[0]['ID']
57-
self.assertEqual('ERROR', self.show_pb(backup_dir, 'node', backup_id)['status'], 'Backup should have ERROR status')
58-
file = os.path.join(backup_dir, 'backups', 'node', backup_id, 'database', path)
59-
self.assertFalse(os.path.isfile(file),
60-
'\n Start LSN was not found in archive but datafiles where copied to backup catalogue.\n For example: {0}\n It is not optimal'.format(file))
67+
self.assertEqual(
68+
'ERROR', self.show_pb(backup_dir, 'node', backup_id)['status'],
69+
'Backup should have ERROR status')
70+
file = os.path.join(
71+
backup_dir, 'backups', 'node',
72+
backup_id, 'database', path)
73+
self.assertFalse(
74+
os.path.isfile(file),
75+
"\n Start LSN was not found in archive but datafiles where "
76+
"copied to backup catalogue.\n For example: {0}\n "
77+
"It is not optimal".format(file))
6178

6279
# Clean after yourself
6380
self.del_test_dir(module_name, fname)

tests/retention_test.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ def test_retention_window_2(self):
7171
self.set_archiving(backup_dir, 'node', node)
7272
node.start()
7373

74-
with open(os.path.join(backup_dir, 'backups', 'node', "pg_probackup.conf"), "a") as conf:
74+
with open(
75+
os.path.join(
76+
backup_dir,
77+
'backups',
78+
'node',
79+
"pg_probackup.conf"), "a") as conf:
7580
conf.write("retention-redundancy = 1\n")
7681
conf.write("retention-window = 1\n")
7782

@@ -86,7 +91,9 @@ def test_retention_window_2(self):
8691
for backup in os.listdir(backups):
8792
if backup == 'pg_probackup.conf':
8893
continue
89-
with open(os.path.join(backups, backup, "backup.control"), "a") as conf:
94+
with open(
95+
os.path.join(
96+
backups, backup, "backup.control"), "a") as conf:
9097
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
9198
datetime.now() - timedelta(days=days_delta)))
9299
days_delta -= 1
@@ -107,7 +114,8 @@ def test_retention_window_2(self):
107114
def test_retention_wal(self):
108115
"""purge backups using window-based retention policy"""
109116
fname = self.id().split('.')[3]
110-
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
117+
node = self.make_simple_node(
118+
base_dir="{0}/{1}/node".format(module_name, fname),
111119
initdb_params=['--data-checksums'],
112120
pg_options={'wal_level': 'replica'}
113121
)
@@ -119,13 +127,17 @@ def test_retention_wal(self):
119127

120128
node.safe_psql(
121129
"postgres",
122-
"create table t_heap as select i as id, md5(i::text) as text, md5(repeat(i::text,10))::tsvector as tsvector from generate_series(0,100500) i")
130+
"create table t_heap as select i as id, md5(i::text) as text, "
131+
"md5(repeat(i::text,10))::tsvector as tsvector "
132+
"from generate_series(0,100500) i")
123133

124134
# Take FULL BACKUP
125135
self.backup_node(backup_dir, 'node', node)
126136
node.safe_psql(
127137
"postgres",
128-
"insert into t_heap select i as id, md5(i::text) as text, md5(repeat(i::text,10))::tsvector as tsvector from generate_series(0,100500) i")
138+
"insert into t_heap select i as id, md5(i::text) as text, "
139+
"md5(repeat(i::text,10))::tsvector as tsvector "
140+
"from generate_series(0,100500) i")
129141

130142
self.backup_node(backup_dir, 'node', node)
131143

@@ -134,18 +146,21 @@ def test_retention_wal(self):
134146
for backup in os.listdir(backups):
135147
if backup == 'pg_probackup.conf':
136148
continue
137-
with open(os.path.join(backups, backup, "backup.control"), "a") as conf:
149+
with open(
150+
os.path.join(
151+
backups, backup, "backup.control"), "a") as conf:
138152
conf.write("recovery_time='{:%Y-%m-%d %H:%M:%S}'\n".format(
139153
datetime.now() - timedelta(days=days_delta)))
140154
days_delta -= 1
141155

142156
# Make backup to be keeped
143157
self.backup_node(backup_dir, 'node', node, backup_type="page")
144158

145-
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 4)
159+
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 3)
146160

147161
# Purge backups
148-
self.delete_expired(backup_dir, 'node')
162+
self.delete_expired(
163+
backup_dir, 'node', options=['--retention-window=2'])
149164
self.assertEqual(len(self.show_pb(backup_dir, 'node')), 2)
150165

151166
# Clean after yourself

0 commit comments

Comments
 (0)