Skip to content

Commit 49a8575

Browse files
committed
tests fixes, del_test_dir added
1 parent 9c7eae6 commit 49a8575

25 files changed

+673
-1060
lines changed

tests/__init__.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@
66
ptrack_move_to_tablespace, ptrack_recovery, ptrack_vacuum, \
77
ptrack_vacuum_bits_frozen, ptrack_vacuum_bits_visibility, \
88
ptrack_vacuum_full, ptrack_vacuum_truncate, pgpro560, pgpro589, \
9-
pgpro688, false_positive, replica
9+
false_positive, replica
1010

1111

1212
def load_tests(loader, tests, pattern):
1313
suite = unittest.TestSuite()
14-
suite.addTests(loader.loadTestsFromModule(replica))
15-
# suite.addTests(loader.loadTestsFromModule(pgpro560))
16-
# suite.addTests(loader.loadTestsFromModule(pgpro589))
17-
# suite.addTests(loader.loadTestsFromModule(pgpro688))
18-
# suite.addTests(loader.loadTestsFromModule(false_positive))
1914
suite.addTests(loader.loadTestsFromModule(init_test))
2015
suite.addTests(loader.loadTestsFromModule(option_test))
2116
suite.addTests(loader.loadTestsFromModule(show_test))
@@ -33,8 +28,9 @@ def load_tests(loader, tests, pattern):
3328
suite.addTests(loader.loadTestsFromModule(ptrack_vacuum_bits_visibility))
3429
suite.addTests(loader.loadTestsFromModule(ptrack_vacuum_full))
3530
suite.addTests(loader.loadTestsFromModule(ptrack_vacuum_truncate))
31+
suite.addTests(loader.loadTestsFromModule(replica))
32+
suite.addTests(loader.loadTestsFromModule(pgpro560))
33+
suite.addTests(loader.loadTestsFromModule(pgpro589))
34+
suite.addTests(loader.loadTestsFromModule(false_positive))
3635

3736
return suite
38-
39-
40-
# ExpectedFailures are bugs, which should be fixed

tests/backup_test.py

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import unittest
22
import os
3-
import six
43
from time import sleep
5-
from helpers.ptrack_helpers import ProbackupTest, ProbackupException
6-
from testgres import stop_all
4+
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
5+
from testgres import stop_all, clean_all
6+
import shutil
77

88

99
class BackupTest(ProbackupTest, unittest.TestCase):
@@ -12,10 +12,6 @@ def __init__(self, *args, **kwargs):
1212
super(BackupTest, self).__init__(*args, **kwargs)
1313
self.module_name = 'backup'
1414

15-
@classmethod
16-
def tearDownClass(cls):
17-
stop_all()
18-
1915
# @unittest.skip("skip")
2016
# @unittest.expectedFailure
2117
# PGPRO-707
@@ -39,8 +35,8 @@ def test_backup_modes_archive(self):
3935
backup_id = self.backup_node(backup_dir, 'node', node)
4036
show_backup = self.show_pb(backup_dir, 'node')[0]
4137

42-
self.assertEqual(show_backup['Status'], six.b("OK"))
43-
self.assertEqual(show_backup['Mode'], six.b("FULL"))
38+
self.assertEqual(show_backup['Status'], "OK")
39+
self.assertEqual(show_backup['Mode'], "FULL")
4440

4541
# postmaster.pid and postmaster.opts shouldn't be copied
4642
excluded = True
@@ -56,8 +52,8 @@ def test_backup_modes_archive(self):
5652

5753
# print self.show_pb(node)
5854
show_backup = self.show_pb(backup_dir, 'node')[1]
59-
self.assertEqual(show_backup['Status'], six.b("OK"))
60-
self.assertEqual(show_backup['Mode'], six.b("PAGE"))
55+
self.assertEqual(show_backup['Status'], "OK")
56+
self.assertEqual(show_backup['Mode'], "PAGE")
6157

6258
# Check parent backup
6359
self.assertEqual(
@@ -68,15 +64,16 @@ def test_backup_modes_archive(self):
6864
self.backup_node(backup_dir, 'node', node, backup_type="ptrack")
6965

7066
show_backup = self.show_pb(backup_dir, 'node')[2]
71-
self.assertEqual(show_backup['Status'], six.b("OK"))
72-
self.assertEqual(show_backup['Mode'], six.b("PTRACK"))
67+
self.assertEqual(show_backup['Status'], "OK")
68+
self.assertEqual(show_backup['Mode'], "PTRACK")
7369

7470
# Check parent backup
7571
self.assertEqual(
7672
page_backup_id,
7773
self.show_pb(backup_dir, 'node', backup_id=show_backup['ID'])["parent-backup-id"])
7874

79-
node.stop()
75+
# Clean after yourself
76+
self.del_test_dir(self.module_name, fname)
8077

8178
# @unittest.skip("skip")
8279
def test_smooth_checkpoint(self):
@@ -93,9 +90,12 @@ def test_smooth_checkpoint(self):
9390
node.start()
9491

9592
self.backup_node(backup_dir, 'node' ,node, options=["-C"])
96-
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], six.b("OK"))
93+
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
9794
node.stop()
9895

96+
# Clean after yourself
97+
self.del_test_dir(self.module_name, fname)
98+
9999
#@unittest.skip("skip")
100100
def test_incremental_backup_without_full(self):
101101
"""page-level backup without validated full backup"""
@@ -115,7 +115,7 @@ def test_incremental_backup_without_full(self):
115115
# we should die here because exception is what we expect to happen
116116
self.assertEqual(1, 0, "Expecting Error because page backup should not be possible without valid full backup.\n Output: {0} \n CMD: {1}".format(
117117
repr(self.output), self.cmd))
118-
except ProbackupException, e:
118+
except ProbackupException as e:
119119
self.assertEqual(e.message,
120120
'ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n',
121121
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
@@ -127,16 +127,17 @@ def test_incremental_backup_without_full(self):
127127
# we should die here because exception is what we expect to happen
128128
self.assertEqual(1, 0, "Expecting Error because page backup should not be possible without valid full backup.\n Output: {0} \n CMD: {1}".format(
129129
repr(self.output), self.cmd))
130-
except ProbackupException, e:
130+
except ProbackupException as e:
131131
self.assertEqual(e.message,
132132
'ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n',
133133
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
134134

135-
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], six.b("ERROR"))
136-
node.stop()
135+
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "ERROR")
136+
137+
# Clean after yourself
138+
self.del_test_dir(self.module_name, fname)
137139

138-
@unittest.expectedFailure
139-
# Need to forcibly validate parent
140+
# @unittest.expectedFailure
140141
def test_incremental_backup_corrupt_full(self):
141142
"""page-level backup with corrupted full backup"""
142143
fname = self.id().split('.')[3]
@@ -151,29 +152,37 @@ def test_incremental_backup_corrupt_full(self):
151152
node.start()
152153

153154
backup_id = self.backup_node(backup_dir, 'node', node)
154-
file = os.path.join(backup_dir, "backups", "node", backup_id.decode("utf-8"), "database", "postgresql.conf")
155+
file = os.path.join(backup_dir, "backups", "node", backup_id, "database", "postgresql.conf")
155156
os.remove(file)
156157

157158
try:
158-
self.backup_node(backup_dir, 'node', node, backup_type="page")
159+
self.validate_pb(backup_dir, 'node')
159160
# we should die here because exception is what we expect to happen
160-
self.assertEqual(1, 0, "Expecting Error because page backup should not be possible without valid full backup.\n Output: {0} \n CMD: {1}".format(
161+
self.assertEqual(1, 0, "Expecting Error because of validation of corrupted backup.\n Output: {0} \n CMD: {1}".format(
161162
repr(self.output), self.cmd))
162-
except ProbackupException, e:
163-
self.assertEqual(e.message,
164-
'ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n',
165-
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
163+
except ProbackupException as e:
164+
self.assertTrue("INFO: Validate backups of the instance 'node'\n" in e.message
165+
and 'WARNING: Backup file "{0}" is not found\n'.format(file) in e.message
166+
and "WARNING: Backup {0} is corrupted\n".format(backup_id) in e.message
167+
and "INFO: Some backups are not valid\n" in e.message,
168+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(repr(e.message), self.cmd))
166169

167-
sleep(1)
170+
try:
171+
self.backup_node(backup_dir, 'node', node, backup_type="page")
172+
# we should die here because exception is what we expect to happen
168173
self.assertEqual(1, 0, "Expecting Error because page backup should not be possible without valid full backup.\n Output: {0} \n CMD: {1}".format(
169174
repr(self.output), self.cmd))
170-
except ProbackupException, e:
175+
except ProbackupException as e:
171176
self.assertEqual(e.message,
172-
'ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n',
173-
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
177+
"ERROR: Valid backup on current timeline is not found. Create new FULL backup before an incremental one.\n",
178+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(repr(e.message), self.cmd))
174179

175-
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], six.b("ERROR"))
176-
node.stop()
180+
# sleep(1)
181+
self.assertEqual(self.show_pb(backup_dir, 'node', backup_id)['status'], "CORRUPT")
182+
self.assertEqual(self.show_pb(backup_dir, 'node')[1]['Status'], "ERROR")
183+
184+
# Clean after yourself
185+
self.del_test_dir(self.module_name, fname)
177186

178187
# @unittest.skip("skip")
179188
def test_ptrack_threads(self):
@@ -190,12 +199,13 @@ def test_ptrack_threads(self):
190199
node.start()
191200

192201
self.backup_node(backup_dir, 'node', node, backup_type="full", options=["-j", "4"])
193-
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], six.b("OK"))
202+
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
194203

195204
self.backup_node(backup_dir, 'node', node, backup_type="ptrack", options=["-j", "4"])
196-
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], six.b("OK"))
205+
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
197206

198-
node.stop()
207+
# Clean after yourself
208+
self.del_test_dir(self.module_name, fname)
199209

200210
# @unittest.skip("skip")
201211
def test_ptrack_threads_stream(self):
@@ -213,7 +223,9 @@ def test_ptrack_threads_stream(self):
213223

214224
self.backup_node(backup_dir, 'node', node, backup_type="full", options=["-j", "4", "--stream"])
215225

216-
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], six.b("OK"))
226+
self.assertEqual(self.show_pb(backup_dir, 'node')[0]['Status'], "OK")
217227
self.backup_node(backup_dir, 'node', node, backup_type="ptrack", options=["-j", "4", "--stream"])
218-
self.assertEqual(self.show_pb(backup_dir, 'node')[1]['Status'], six.b("OK"))
219-
node.stop()
228+
self.assertEqual(self.show_pb(backup_dir, 'node')[1]['Status'], "OK")
229+
230+
# Clean after yourself
231+
self.del_test_dir(self.module_name, fname)

tests/delete_test.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import unittest
22
import os
3-
import six
4-
from helpers.ptrack_helpers import ProbackupTest, ProbackupException
5-
from testgres import stop_all
3+
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
4+
from testgres import stop_all, clean_all
65
import subprocess
6+
import shutil
77

88

99
class DeleteTest(ProbackupTest, unittest.TestCase):
@@ -12,10 +12,6 @@ def __init__(self, *args, **kwargs):
1212
super(DeleteTest, self).__init__(*args, **kwargs)
1313
self.module_name = 'delete'
1414

15-
@classmethod
16-
def tearDownClass(cls):
17-
stop_all()
18-
1915
# @unittest.skip("skip")
2016
# @unittest.expectedFailure
2117
def test_delete_full_backups(self):
@@ -55,7 +51,8 @@ def test_delete_full_backups(self):
5551
self.assertEqual(show_backups[0]['ID'], id_1)
5652
self.assertEqual(show_backups[1]['ID'], id_3)
5753

58-
node.stop()
54+
# Clean after yourself
55+
self.del_test_dir(self.module_name, fname)
5956

6057
def test_delete_increment_page(self):
6158
"""delete increment and all after him"""
@@ -88,12 +85,13 @@ def test_delete_increment_page(self):
8885
show_backups = self.show_pb(backup_dir, 'node')
8986
self.assertEqual(len(show_backups), 2)
9087

91-
self.assertEqual(show_backups[0]['Mode'], six.b("FULL"))
92-
self.assertEqual(show_backups[0]['Status'], six.b("OK"))
93-
self.assertEqual(show_backups[1]['Mode'], six.b("FULL"))
94-
self.assertEqual(show_backups[1]['Status'], six.b("OK"))
88+
self.assertEqual(show_backups[0]['Mode'], "FULL")
89+
self.assertEqual(show_backups[0]['Status'], "OK")
90+
self.assertEqual(show_backups[1]['Mode'], "FULL")
91+
self.assertEqual(show_backups[1]['Status'], "OK")
9592

96-
node.stop()
93+
# Clean after yourself
94+
self.del_test_dir(self.module_name, fname)
9795

9896
def test_delete_increment_ptrack(self):
9997
"""delete increment and all after him"""
@@ -126,9 +124,10 @@ def test_delete_increment_ptrack(self):
126124
show_backups = self.show_pb(backup_dir, 'node')
127125
self.assertEqual(len(show_backups), 2)
128126

129-
self.assertEqual(show_backups[0]['Mode'], six.b("FULL"))
130-
self.assertEqual(show_backups[0]['Status'], six.b("OK"))
131-
self.assertEqual(show_backups[1]['Mode'], six.b("FULL"))
132-
self.assertEqual(show_backups[1]['Status'], six.b("OK"))
127+
self.assertEqual(show_backups[0]['Mode'], "FULL")
128+
self.assertEqual(show_backups[0]['Status'], "OK")
129+
self.assertEqual(show_backups[1]['Mode'], "FULL")
130+
self.assertEqual(show_backups[1]['Status'], "OK")
133131

134-
node.stop()
132+
# Clean after yourself
133+
self.del_test_dir(self.module_name, fname)

0 commit comments

Comments
 (0)