Skip to content

Commit b269c84

Browse files
committed
tests: new module "exclude.py" and minor fixes
1 parent b16dd21 commit b269c84

File tree

7 files changed

+203
-46
lines changed

7 files changed

+203
-46
lines changed

tests/__init__.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,24 @@
77
ptrack_vacuum_bits_frozen, ptrack_vacuum_bits_visibility, \
88
ptrack_vacuum_full, ptrack_vacuum_truncate, pgpro560, pgpro589, \
99
false_positive, replica, compression, page, ptrack, archive, \
10-
cfs_backup, cfs_restore, cfs_validate_backup
10+
exclude, cfs_backup, cfs_restore, cfs_validate_backup
1111

1212

1313
def load_tests(loader, tests, pattern):
1414
suite = unittest.TestSuite()
15-
suite.addTests(loader.loadTestsFromModule(init_test))
16-
suite.addTests(loader.loadTestsFromModule(option_test))
17-
suite.addTests(loader.loadTestsFromModule(show_test))
15+
suite.addTests(loader.loadTestsFromModule(archive))
1816
suite.addTests(loader.loadTestsFromModule(backup_test))
17+
# suite.addTests(loader.loadTestsFromModule(cfs_backup))
18+
# suite.addTests(loader.loadTestsFromModule(cfs_restore))
19+
# suite.addTests(loader.loadTestsFromModule(cfs_validate_backup))
20+
# suite.addTests(loader.loadTestsFromModule(logging))
21+
suite.addTests(loader.loadTestsFromModule(compression))
1922
suite.addTests(loader.loadTestsFromModule(delete_test))
20-
suite.addTests(loader.loadTestsFromModule(restore_test))
21-
suite.addTests(loader.loadTestsFromModule(validate_test))
22-
suite.addTests(loader.loadTestsFromModule(retention_test))
23+
suite.addTests(loader.loadTestsFromModule(exclude))
24+
suite.addTests(loader.loadTestsFromModule(false_positive))
25+
suite.addTests(loader.loadTestsFromModule(init_test))
26+
suite.addTests(loader.loadTestsFromModule(option_test))
27+
suite.addTests(loader.loadTestsFromModule(page))
2328
suite.addTests(loader.loadTestsFromModule(ptrack))
2429
suite.addTests(loader.loadTestsFromModule(ptrack_clean))
2530
suite.addTests(loader.loadTestsFromModule(ptrack_cluster))
@@ -31,15 +36,12 @@ def load_tests(loader, tests, pattern):
3136
suite.addTests(loader.loadTestsFromModule(ptrack_vacuum_full))
3237
suite.addTests(loader.loadTestsFromModule(ptrack_vacuum_truncate))
3338
suite.addTests(loader.loadTestsFromModule(replica))
39+
suite.addTests(loader.loadTestsFromModule(restore_test))
40+
suite.addTests(loader.loadTestsFromModule(retention_test))
41+
suite.addTests(loader.loadTestsFromModule(show_test))
42+
suite.addTests(loader.loadTestsFromModule(validate_test))
3443
suite.addTests(loader.loadTestsFromModule(pgpro560))
3544
suite.addTests(loader.loadTestsFromModule(pgpro589))
36-
suite.addTests(loader.loadTestsFromModule(false_positive))
37-
suite.addTests(loader.loadTestsFromModule(compression))
38-
suite.addTests(loader.loadTestsFromModule(page))
39-
suite.addTests(loader.loadTestsFromModule(archive))
40-
# suite.addTests(loader.loadTestsFromModule(cfs_backup))
41-
# suite.addTests(loader.loadTestsFromModule(cfs_restore))
42-
# suite.addTests(loader.loadTestsFromModule(cfs_validate_backup))
4345

4446
return suite
4547

tests/backup_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_smooth_checkpoint(self):
9393
# Clean after yourself
9494
self.del_test_dir(module_name, fname)
9595

96-
#@unittest.skip("skip")
96+
# @unittest.skip("skip")
9797
def test_incremental_backup_without_full(self):
9898
"""page-level backup without validated full backup"""
9999
fname = self.id().split('.')[3]
@@ -134,7 +134,7 @@ def test_incremental_backup_without_full(self):
134134
# Clean after yourself
135135
self.del_test_dir(module_name, fname)
136136

137-
# @unittest.expectedFailure
137+
# @unittest.skip("skip")
138138
def test_incremental_backup_corrupt_full(self):
139139
"""page-level backup with corrupted full backup"""
140140
fname = self.id().split('.')[3]

tests/cfs_backup.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_fullbackup_after_create_table(self):
151151
"ERROR: .cfm files not found in backup dir"
152152
)
153153

154-
@unittest.expectedFailure
154+
# @unittest.expectedFailure
155155
# @unittest.skip("skip")
156156
# PGPRO-1018 invalid file size
157157
def test_fullbackup_after_create_table_stream(self):
@@ -193,7 +193,7 @@ def test_fullbackup_after_create_table_stream(self):
193193
)
194194

195195
# --- Section: Incremental from empty tablespace --- #
196-
@unittest.expectedFailure
196+
# @unittest.expectedFailure
197197
# @unittest.skip("skip")
198198
def test_fullbackup_empty_tablespace_ptrack_after_create_table(self):
199199
"""
@@ -244,7 +244,7 @@ def test_fullbackup_empty_tablespace_ptrack_after_create_table(self):
244244
"ERROR: .cfm files not found in backup dir"
245245
)
246246

247-
@unittest.expectedFailure
247+
# @unittest.expectedFailure
248248
# @unittest.skip("skip")
249249
def test_fullbackup_empty_tablespace_ptrack_after_create_table_stream(self):
250250
"""
@@ -406,7 +406,7 @@ def test_fullbackup_empty_tablespace_page_after_create_table_stream(self):
406406
)
407407

408408
# --- Section: Incremental from fill tablespace --- #
409-
@unittest.expectedFailure
409+
# @unittest.expectedFailure
410410
# @unittest.skip("skip")
411411
def test_fullbackup_after_create_table_ptrack_after_create_table(self):
412412
"""
@@ -464,7 +464,7 @@ def test_fullbackup_after_create_table_ptrack_after_create_table(self):
464464
)
465465
)
466466

467-
@unittest.expectedFailure
467+
# @unittest.expectedFailure
468468
# @unittest.skip("skip")
469469
def test_fullbackup_after_create_table_ptrack_after_create_table_stream(self):
470470
"""
@@ -822,7 +822,7 @@ def test_fullbackup_after_create_table_page_after_create_table_stream(self):
822822
)
823823

824824
# --- Make backup with not valid data(broken .cfm) --- #
825-
@unittest.expectedFailure
825+
# @unittest.expectedFailure
826826
# @unittest.skip("skip")
827827
def test_delete_random_cfm_file_from_tablespace_dir(self):
828828
self.node.safe_psql(
@@ -846,7 +846,7 @@ def test_delete_random_cfm_file_from_tablespace_dir(self):
846846
self.backup_node,self.backup_dir, 'node', self.node, backup_type='full'
847847
)
848848

849-
@unittest.expectedFailure
849+
# @unittest.expectedFailure
850850
# @unittest.skip("skip")
851851
def test_delete_file_pg_compression_from_tablespace_dir(self):
852852
os.remove(find_by_name([self.get_tblspace_path(self.node, tblspace_name)], ['pg_compression'])[0])
@@ -856,7 +856,7 @@ def test_delete_file_pg_compression_from_tablespace_dir(self):
856856
self.backup_node,self.backup_dir, 'node', self.node, backup_type='full'
857857
)
858858

859-
@unittest.expectedFailure
859+
# @unittest.expectedFailure
860860
# @unittest.skip("skip")
861861
def test_delete_random_data_file_from_tablespace_dir(self):
862862
self.node.safe_psql(
@@ -880,7 +880,7 @@ def test_delete_random_data_file_from_tablespace_dir(self):
880880
self.backup_node,self.backup_dir, 'node', self.node, backup_type='full'
881881
)
882882

883-
@unittest.expectedFailure
883+
# @unittest.expectedFailure
884884
# @unittest.skip("skip")
885885
def test_broken_random_cfm_file_into_tablespace_dir(self):
886886
self.node.safe_psql(
@@ -904,7 +904,7 @@ def test_broken_random_cfm_file_into_tablespace_dir(self):
904904
self.backup_node,self.backup_dir, 'node', self.node, backup_type='full'
905905
)
906906

907-
@unittest.expectedFailure
907+
# @unittest.expectedFailure
908908
# @unittest.skip("skip")
909909
def test_broken_random_data_file_into_tablespace_dir(self):
910910
self.node.safe_psql(
@@ -928,7 +928,7 @@ def test_broken_random_data_file_into_tablespace_dir(self):
928928
self.backup_node,self.backup_dir, 'node', self.node, backup_type='full'
929929
)
930930

931-
@unittest.expectedFailure
931+
# @unittest.expectedFailure
932932
# @unittest.skip("skip")
933933
def test_broken_file_pg_compression_into_tablespace_dir(self):
934934

tests/class_check1.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/exclude.py

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
import os
2+
import unittest
3+
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
4+
5+
6+
module_name = 'exclude'
7+
8+
9+
class ExcludeTest(ProbackupTest, unittest.TestCase):
10+
11+
# @unittest.skip("skip")
12+
# @unittest.expectedFailure
13+
def test_exclude_temp_tables(self):
14+
"""make node without archiving, create temp table, take full backup, check that temp table not present in backup catalogue"""
15+
fname = self.id().split('.')[3]
16+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
17+
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
18+
set_replication=True,
19+
initdb_params=['--data-checksums'],
20+
pg_options={'wal_level': 'replica', 'max_wal_senders': '2', 'shared_buffers': '1GB',
21+
"fsync": "off", 'ptrack_enable': 'on'}
22+
)
23+
24+
self.init_pb(backup_dir)
25+
self.add_instance(backup_dir, 'node', node)
26+
node.start()
27+
28+
conn = node.connect()
29+
with node.connect("postgres") as conn:
30+
31+
conn.execute("create temp table test as select generate_series(0,50050000)::text")
32+
conn.commit()
33+
34+
temp_schema_name = conn.execute("SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema()")[0][0]
35+
conn.commit()
36+
37+
temp_toast_schema_name = "pg_toast_" + temp_schema_name.replace("pg_", "")
38+
conn.commit()
39+
40+
conn.execute("create index test_idx on test (generate_series)")
41+
conn.commit()
42+
43+
heap_path = conn.execute("select pg_relation_filepath('test')")[0][0]
44+
conn.commit()
45+
46+
index_path = conn.execute("select pg_relation_filepath('test_idx')")[0][0]
47+
conn.commit()
48+
49+
heap_oid = conn.execute("select 'test'::regclass::oid")[0][0]
50+
conn.commit()
51+
52+
toast_path = conn.execute("select pg_relation_filepath('{0}.{1}')".format(temp_toast_schema_name, "pg_toast_" + str(heap_oid)))[0][0]
53+
conn.commit()
54+
55+
toast_idx_path = conn.execute("select pg_relation_filepath('{0}.{1}')".format(temp_toast_schema_name, "pg_toast_" + str(heap_oid) + "_index"))[0][0]
56+
conn.commit()
57+
58+
temp_table_filename = os.path.basename(heap_path)
59+
temp_idx_filename = os.path.basename(index_path)
60+
temp_toast_filename = os.path.basename(toast_path)
61+
temp_idx_toast_filename = os.path.basename(toast_idx_path)
62+
63+
self.backup_node(backup_dir, 'node', node, backup_type='full', options=['--stream'])
64+
65+
for root, dirs, files in os.walk(backup_dir):
66+
for file in files:
67+
if file in [temp_table_filename, temp_table_filename + ".1",
68+
temp_idx_filename,
69+
temp_idx_filename + ".1",
70+
temp_toast_filename,
71+
temp_toast_filename + ".1",
72+
temp_idx_toast_filename,
73+
temp_idx_toast_filename + ".1"]:
74+
self.assertEqual(1, 0, "Found temp table file in backup catalogue.\n Filepath: {0}".format(file))
75+
76+
# Clean after yourself
77+
self.del_test_dir(module_name, fname)
78+
79+
# @unittest.skip("skip")
80+
def test_exclude_unlogged_tables(self):
81+
"""make node without archiving, create temp table, take full backup, check that temp table not present in backup catalogue"""
82+
fname = self.id().split('.')[3]
83+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
84+
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
85+
set_replication=True,
86+
initdb_params=['--data-checksums'],
87+
pg_options={'wal_level': 'replica', 'max_wal_senders': '2', "shared_buffers": "1GB", "fsync": "off", 'ptrack_enable': 'on'}
88+
)
89+
90+
self.init_pb(backup_dir)
91+
self.add_instance(backup_dir, 'node', node)
92+
node.start()
93+
94+
conn = node.connect()
95+
with node.connect("postgres") as conn:
96+
97+
conn.execute("create unlogged table test as select generate_series(0,50050000)::text")
98+
conn.commit()
99+
100+
conn.execute("create index test_idx on test (generate_series)")
101+
conn.commit()
102+
103+
heap_path = conn.execute("select pg_relation_filepath('test')")[0][0]
104+
conn.commit()
105+
106+
index_path = conn.execute("select pg_relation_filepath('test_idx')")[0][0]
107+
conn.commit()
108+
index_init_path = index_path + "_init"
109+
110+
heap_oid = conn.execute("select 'test'::regclass::oid")[0][0]
111+
conn.commit()
112+
113+
toast_path = conn.execute("select pg_relation_filepath('{0}.{1}')".format("pg_toast", "pg_toast_" + str(heap_oid)))[0][0]
114+
conn.commit()
115+
toast_init_path = toast_path + "_init"
116+
117+
toast_idx_path = conn.execute("select pg_relation_filepath('{0}.{1}')".format("pg_toast", "pg_toast_" + str(heap_oid) + "_index"))[0][0]
118+
conn.commit()
119+
toast_index_idx_path = toast_idx_path + "_init"
120+
121+
unlogged_heap_filename = os.path.basename(heap_path)
122+
unlogged_heap_init_filename = unlogged_heap_filename + "_init"
123+
124+
unlogged_idx_filename = os.path.basename(index_path)
125+
unlogged_idx_init_filename = unlogged_idx_filename + "_init"
126+
127+
unlogged_toast_filename = os.path.basename(toast_path)
128+
unlogged_toast_init_filename = unlogged_toast_filename + "_init"
129+
130+
unlogged_idx_toast_filename = os.path.basename(toast_idx_path)
131+
unlogged_idx_toast_init_filename = unlogged_idx_toast_filename + "_init"
132+
133+
self.backup_node(backup_dir, 'node', node, backup_type='full', options=['--stream'])
134+
135+
found_unlogged_heap_init = False
136+
found_unlogged_idx_init = False
137+
found_unlogged_toast = False
138+
found_unlogged_idx_toast_init = False
139+
for root, dirs, files in os.walk(backup_dir):
140+
for file in files:
141+
if file in [unlogged_heap_filename, unlogged_heap_filename + ".1",
142+
unlogged_idx_filename,
143+
unlogged_idx_filename + ".1",
144+
unlogged_toast_filename,
145+
unlogged_toast_filename + ".1",
146+
unlogged_idx_toast_filename,
147+
unlogged_idx_toast_filename + ".1"]:
148+
self.assertTrue(False, "Found unlogged table file in backup catalogue.\n Filepath: {0}".format(file))
149+
150+
if file == unlogged_heap_init_filename:
151+
found_unlogged_heap_init = True
152+
153+
if file == unlogged_idx_init_filename:
154+
found_unlogged_idx_init = True
155+
156+
if file == unlogged_toast_init_filename:
157+
found_unlogged_toast = True
158+
159+
if file == unlogged_idx_toast_init_filename:
160+
found_unlogged_idx_toast_init = True
161+
162+
self.assertTrue(found_unlogged_heap_init, "{0} is not found in backup catalogue".format(unlogged_heap_init_filename));
163+
self.assertTrue(found_unlogged_idx_init, "{0} is not found in backup catalogue".format(unlogged_idx_init_filename));
164+
self.assertTrue(found_unlogged_toast, "{0} is not found in backup catalogue".format(unlogged_toast_filename));
165+
self.assertTrue(found_unlogged_idx_toast_init, "{0} is not found in backup catalogue".format(unlogged_idx_toast_init_filename));
166+
167+
# Clean after yourself
168+
self.del_test_dir(module_name, fname)

tests/helpers/ptrack_helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ def show_pb(self, backup_dir, instance=None, backup_id=None, options=[], as_text
469469
for i in header_split:
470470
if i == '':
471471
header_split.remove(i)
472+
continue
473+
header_split = [header_element.rstrip() for header_element in header_split]
472474
for backup_record in body:
473475
# split string in list with string for every backup record element
474476
backup_record_split = re.split(" +", backup_record)
@@ -669,7 +671,7 @@ def compare_pgdata(self, original_pgdata, restored_pgdata):
669671
for file in original_pgdata['files']:
670672
if file in restored_pgdata['files']:
671673
if original_pgdata['files'][file] != restored_pgdata['files'][file]:
672-
error_message += '\nChecksumm mismatch.\n File_old: {0}\n Checksumm_old: {1}\n File_new: {2}\n Checksumm_mew: {3}\n'.format(
674+
error_message += '\nChecksumm mismatch.\n File_old: {0}\n Checksumm_old: {1}\n File_new: {2}\n Checksumm_new: {3}\n'.format(
673675
os.path.join(original_pgdata['pgdata'], file),
674676
original_pgdata['files'][file],
675677
os.path.join(restored_pgdata['pgdata'], file),

tests/pgpro560.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ def test_pgpro560_systemid_mismatch(self):
7373
self.add_instance(backup_dir, 'node1', node1)
7474

7575
try:
76-
self.backup_node(backup_dir, 'node1', node1, data_dir=node2.data_dir, options=['--stream'])
76+
self.backup_node(backup_dir, 'node1', node2, options=['--stream'])
7777
# we should die here because exception is what we expect to happen
78-
self.assertEqual(1, 0, "Expecting Error because of of SYSTEM ID mismatch.\n Output: {0} \n CMD: {1}".format(
78+
self.assertEqual(1, 0, "Expecting Error because of SYSTEM ID mismatch.\n Output: {0} \n CMD: {1}".format(
7979
repr(self.output), self.cmd))
8080
except ProbackupException as e:
8181
self.assertTrue(
8282
'ERROR: Backup data directory was initialized for system id' in e.message
83-
and 'but target backup directory system id is' in e.message,
83+
and 'but connected instance system id is' in e.message,
8484
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
8585

8686
try:

0 commit comments

Comments
 (0)