Skip to content

Commit 2bd2b6e

Browse files
committed
tests fixes
1 parent 4123b76 commit 2bd2b6e

File tree

6 files changed

+67
-21
lines changed

6 files changed

+67
-21
lines changed

tests/Readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[см wiki](https://confluence.postgrespro.ru/display/DEV/pg_probackup)
2+
3+
```
4+
Note: For now there are tests only for Linix
5+
```
6+
7+
```
8+
export PG_CONFIG=/path/to/pg_config
9+
export PGPRO_PARANOIA_MODE=ON/OFF
10+
python -m unittest [-v] tests
11+
```

tests/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ def load_tests(loader, tests, pattern):
5252
# ptrack backup on replica should work correctly
5353
# archive:
5454
# immediate recovery and full recovery
55+
# 10vanilla_1.3ptrack +
56+
# 10vanilla+
57+
# 9.6vanilla_1.3ptrack +

tests/archive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def test_arhive_push_file_exists(self):
233233

234234
os.remove(file)
235235
sleep(5)
236-
node.safe_psql('postgres', 'select pg_switch_wal()')
236+
self.switch_wal_segment(node)
237237

238238
with open(log_file, 'r') as f:
239239
log_content = f.read()

tests/helpers/ptrack_helpers.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55
import shutil
66
import six
7-
from testgres import get_new_node, clean_all
7+
from testgres import get_new_node, clean_all, version_to_num
88
import hashlib
99
import re
1010
import pwd
@@ -123,6 +123,12 @@ def __init__(self, *args, **kwargs):
123123

124124
self.test_env["LC_MESSAGES"] = "C"
125125
self.test_env["LC_TIME"] = "C"
126+
127+
self.paranoia = False
128+
if 'PGPRO_PARANOIA_MODE' in self.test_env:
129+
if self.test_env['PGPRO_PARANOIA_MODE'] == 'ON':
130+
self.paranoia = True
131+
126132
self.helpers_path = os.path.dirname(os.path.realpath(__file__))
127133
self.dir_path = os.path.abspath(os.path.join(self.helpers_path, os.pardir))
128134
self.tmp_path = os.path.abspath(os.path.join(self.dir_path, 'tmp_dirs'))
@@ -582,6 +588,13 @@ def get_username(self):
582588
""" Returns current user name """
583589
return pwd.getpwuid(os.getuid())[0]
584590

591+
def switch_wal_segment(self, node):
592+
""" Execute pg_switch_wal/xlog() in given node"""
593+
if version_to_num(node.safe_psql("postgres", "show server_version")) >= version_to_num('10.0'):
594+
node.safe_psql("postgres", "select pg_switch_wal()")
595+
else:
596+
node.safe_psql("postgres", "select pg_switch_xlog()")
597+
585598
def del_test_dir(self, module_name, fname):
586599
""" Del testdir and optimistically try to del module dir"""
587600
try:

tests/ptrack.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,15 @@ def test_ptrack_stream(self):
140140
self.restore_node(backup_dir, 'node', node, backup_id=ptrack_backup_id, options=["-j", "4"]),
141141
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(self.output), self.cmd))
142142
pgdata_restored = self.pgdata_content(node.data_dir)
143-
# self.compare_pgdata(pgdata, pgdata_restored)
144143
node.start()
145144
while node.safe_psql("postgres", "select pg_is_in_recovery()") == 't\n':
146145
time.sleep(1)
147146
ptrack_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap")
148147
self.assertEqual(ptrack_result, ptrack_result_new)
149148

149+
if self.paranoia:
150+
self.compare_pgdata(pgdata, pgdata_restored)
151+
150152
# Clean after yourself
151153
self.del_test_dir(module_name, fname)
152154

@@ -203,12 +205,15 @@ def test_ptrack_archive(self):
203205
self.restore_node(backup_dir, 'node', node, backup_id=ptrack_backup_id, options=["-j", "4", "--time={0}".format(ptrack_target_time)]),
204206
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(self.output), self.cmd))
205207
pgdata_restored = self.pgdata_content(node.data_dir)
206-
# self.compare_pgdata(pgdata, pgdata_restored)
207208
node.start()
208209
while node.safe_psql("postgres", "select pg_is_in_recovery()") == 't\n':
209210
time.sleep(1)
210211
ptrack_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap")
211212
self.assertEqual(ptrack_result, ptrack_result_new)
213+
214+
if self.paranoia:
215+
self.compare_pgdata(pgdata, pgdata_restored)
216+
212217
node.cleanup()
213218

214219
# Clean after yourself
@@ -401,8 +406,9 @@ def test_create_db(self):
401406
node_restored.cleanup()
402407
# COMPARE PHYSICAL CONTENT
403408
self.restore_node(backup_dir, 'node', node_restored, backup_id=backup_id, options=["-j", "4"])
404-
pgdata_new = self.pgdata_content(node_restored.data_dir)
405-
# self.compare_pgdata(pgdata, pgdata_restored)
409+
pgdata_restored = self.pgdata_content(node_restored.data_dir)
410+
if self.paranoia:
411+
self.compare_pgdata(pgdata, pgdata_restored)
406412

407413
# START RESTORED NODE
408414
node_restored.append_conf("postgresql.auto.conf", "port = {0}".format(node_restored.port))
@@ -424,8 +430,9 @@ def test_create_db(self):
424430
node_restored.start()
425431

426432
# COMPARE PHYSICAL CONTENT
427-
pgdata_new = self.pgdata_content(node_restored.data_dir)
428-
# self.compare_pgdata(pgdata, pgdata_restored)
433+
pgdata_restored = self.pgdata_content(node_restored.data_dir)
434+
if self.paranoia:
435+
self.compare_pgdata(pgdata, pgdata_restored)
429436

430437
try:
431438
node_restored.safe_psql('db1', 'select 1')
@@ -485,8 +492,7 @@ def test_alter_table_set_tablespace_ptrack(self):
485492
])
486493

487494
# GET RESTORED PGDATA AND COMPARE
488-
pgdata_new = self.pgdata_content(node_restored.data_dir)
489-
# self.compare_pgdata(pgdata, pgdata_new)
495+
pgdata_restored = self.pgdata_content(node_restored.data_dir)
490496
# START RESTORED NODE
491497
node_restored.append_conf('postgresql.auto.conf', 'port = {0}'.format(node_restored.port))
492498
node_restored.start()
@@ -496,6 +502,8 @@ def test_alter_table_set_tablespace_ptrack(self):
496502
result_new = node_restored.safe_psql("postgres", "select * from t_heap")
497503

498504
self.assertEqual(result, result_new, 'lost some data after restore')
505+
if self.paranoia:
506+
self.compare_pgdata(pgdata, pgdata_restored)
499507

500508
# Clean after yourself
501509
self.del_test_dir(module_name, fname)
@@ -538,9 +546,10 @@ def test_alter_database_set_tablespace_ptrack(self):
538546
"-T", "{0}={1}".format(self.get_tblspace_path(node,'somedata'), self.get_tblspace_path(node_restored,'somedata'))])
539547

540548
# GET PHYSICAL CONTENT
541-
pgdata_new = self.pgdata_content(node_restored.data_dir)
549+
pgdata_restored = self.pgdata_content(node_restored.data_dir)
542550
# COMPARE PHYSICAL CONTENT
543-
# self.compare_pgdata(pgdata, pgdata_restored)
551+
if self.paranoia:
552+
self.compare_pgdata(pgdata, pgdata_restored)
544553
# START RESTORED NODE
545554
node_restored.start()
546555

@@ -649,9 +658,8 @@ def test_ptrack_alter_tablespace(self):
649658
"-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new)])
650659
result = node.safe_psql("postgres", "select * from t_heap")
651660

652-
pgdata_new = self.pgdata_content(restored_node.data_dir)
653-
# COMPARE PHYSICAL CONTENT
654-
# self.compare_pgdata(pgdata, pgdata_restored)
661+
pgdata_restored = self.pgdata_content(restored_node.data_dir)
662+
655663
# START RESTORED NODE
656664
restored_node.append_conf("postgresql.auto.conf", "port = {0}".format(restored_node.port))
657665
restored_node.start()
@@ -660,6 +668,11 @@ def test_ptrack_alter_tablespace(self):
660668

661669
result_new = restored_node.safe_psql("postgres", "select * from t_heap")
662670
self.assertEqual(result, result_new)
671+
672+
# COMPARE PHYSICAL CONTENT
673+
if self.paranoia:
674+
self.compare_pgdata(pgdata, pgdata_restored)
675+
663676
restored_node.cleanup()
664677
shutil.rmtree(tblspc_path_new, ignore_errors=True)
665678

@@ -675,9 +688,8 @@ def test_ptrack_alter_tablespace(self):
675688
"-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new)])
676689
restored_node.append_conf("postgresql.auto.conf", "port = {0}".format(restored_node.port))
677690

678-
# COMPARE PHYSICAL CONTENT
679-
pgdata_new = self.pgdata_content(restored_node.data_dir)
680-
# self.compare_pgdata(pgdata, pgdata_restored)
691+
# GET PHYSICAL CONTENT
692+
pgdata_restored = self.pgdata_content(restored_node.data_dir)
681693

682694
# START RESTORED NODE
683695
restored_node.start()
@@ -687,13 +699,16 @@ def test_ptrack_alter_tablespace(self):
687699
result_new = restored_node.safe_psql("postgres", "select * from t_heap")
688700
self.assertEqual(result, result_new)
689701

702+
if self.paranoia:
703+
# COMPARE PHYSICAL CONTENT
704+
self.compare_pgdata(pgdata, pgdata_restored)
705+
690706
# Clean after yourself
691707
self.del_test_dir(module_name, fname)
692708

693709
# @unittest.skip("skip")
694710
def test_relation_with_multiple_segments(self):
695711
"""Make node, create table, alter table tablespace, take ptrack backup, move table from tablespace, take ptrack backup"""
696-
self.maxDiff = None
697712
fname = self.id().split('.')[3]
698713
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
699714
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
@@ -736,7 +751,6 @@ def test_relation_with_multiple_segments(self):
736751

737752
# GET PHYSICAL CONTENT FROM NODE_RESTORED
738753
pgdata_restored = self.pgdata_content(restored_node.data_dir)
739-
# self.compare_pgdata(pgdata, pgdata_restored)
740754

741755
# START RESTORED NODE
742756
restored_node.append_conf("postgresql.auto.conf", "port = {0}".format(restored_node.port))
@@ -745,7 +759,12 @@ def test_relation_with_multiple_segments(self):
745759
time.sleep(1)
746760

747761
result_new = restored_node.safe_psql("postgres", "select * from pgbench_accounts")
762+
763+
# COMPARE RESTORED FILES
748764
self.assertEqual(result, result_new)
749765

766+
if self.paranoia:
767+
self.compare_pgdata(pgdata, pgdata_restored)
768+
750769
# Clean after yourself
751770
self.del_test_dir(module_name, fname)

tests/validate_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_validate_wal_unreal_values(self):
7676
res = con.execute("INSERT INTO tbl0005 VALUES ('inserted') RETURNING (xmin)")
7777
con.commit()
7878
target_xid = res[0][0]
79-
node.execute("postgres", "SELECT pg_switch_wal()")
79+
self.switch_wal_segment(node)
8080

8181
self.assertIn("INFO: backup validation completed successfully",
8282
self.validate_pb(backup_dir, 'node', options=["--xid={0}".format(target_xid)]),

0 commit comments

Comments
 (0)