You've already forked pg_probackup
mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-09-16 09:26:30 +02:00
tests fixes
This commit is contained in:
11
tests/Readme.md
Normal file
11
tests/Readme.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[см wiki](https://confluence.postgrespro.ru/display/DEV/pg_probackup)
|
||||||
|
|
||||||
|
```
|
||||||
|
Note: For now there are tests only for Linix
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
export PG_CONFIG=/path/to/pg_config
|
||||||
|
export PGPRO_PARANOIA_MODE=ON/OFF
|
||||||
|
python -m unittest [-v] tests
|
||||||
|
```
|
@@ -52,3 +52,6 @@ def load_tests(loader, tests, pattern):
|
|||||||
# ptrack backup on replica should work correctly
|
# ptrack backup on replica should work correctly
|
||||||
# archive:
|
# archive:
|
||||||
# immediate recovery and full recovery
|
# immediate recovery and full recovery
|
||||||
|
# 10vanilla_1.3ptrack +
|
||||||
|
# 10vanilla+
|
||||||
|
# 9.6vanilla_1.3ptrack +
|
||||||
|
@@ -233,7 +233,7 @@ class ArchiveTest(ProbackupTest, unittest.TestCase):
|
|||||||
|
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
sleep(5)
|
sleep(5)
|
||||||
node.safe_psql('postgres', 'select pg_switch_wal()')
|
self.switch_wal_segment(node)
|
||||||
|
|
||||||
with open(log_file, 'r') as f:
|
with open(log_file, 'r') as f:
|
||||||
log_content = f.read()
|
log_content = f.read()
|
||||||
|
@@ -4,7 +4,7 @@ from sys import exit, argv, version_info
|
|||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
import six
|
import six
|
||||||
from testgres import get_new_node, clean_all
|
from testgres import get_new_node, clean_all, version_to_num
|
||||||
import hashlib
|
import hashlib
|
||||||
import re
|
import re
|
||||||
import pwd
|
import pwd
|
||||||
@@ -123,6 +123,12 @@ class ProbackupTest(object):
|
|||||||
|
|
||||||
self.test_env["LC_MESSAGES"] = "C"
|
self.test_env["LC_MESSAGES"] = "C"
|
||||||
self.test_env["LC_TIME"] = "C"
|
self.test_env["LC_TIME"] = "C"
|
||||||
|
|
||||||
|
self.paranoia = False
|
||||||
|
if 'PGPRO_PARANOIA_MODE' in self.test_env:
|
||||||
|
if self.test_env['PGPRO_PARANOIA_MODE'] == 'ON':
|
||||||
|
self.paranoia = True
|
||||||
|
|
||||||
self.helpers_path = os.path.dirname(os.path.realpath(__file__))
|
self.helpers_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
self.dir_path = os.path.abspath(os.path.join(self.helpers_path, os.pardir))
|
self.dir_path = os.path.abspath(os.path.join(self.helpers_path, os.pardir))
|
||||||
self.tmp_path = os.path.abspath(os.path.join(self.dir_path, 'tmp_dirs'))
|
self.tmp_path = os.path.abspath(os.path.join(self.dir_path, 'tmp_dirs'))
|
||||||
@@ -582,6 +588,13 @@ class ProbackupTest(object):
|
|||||||
""" Returns current user name """
|
""" Returns current user name """
|
||||||
return pwd.getpwuid(os.getuid())[0]
|
return pwd.getpwuid(os.getuid())[0]
|
||||||
|
|
||||||
|
def switch_wal_segment(self, node):
|
||||||
|
""" Execute pg_switch_wal/xlog() in given node"""
|
||||||
|
if version_to_num(node.safe_psql("postgres", "show server_version")) >= version_to_num('10.0'):
|
||||||
|
node.safe_psql("postgres", "select pg_switch_wal()")
|
||||||
|
else:
|
||||||
|
node.safe_psql("postgres", "select pg_switch_xlog()")
|
||||||
|
|
||||||
def del_test_dir(self, module_name, fname):
|
def del_test_dir(self, module_name, fname):
|
||||||
""" Del testdir and optimistically try to del module dir"""
|
""" Del testdir and optimistically try to del module dir"""
|
||||||
try:
|
try:
|
||||||
|
@@ -140,13 +140,15 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
self.restore_node(backup_dir, 'node', node, backup_id=ptrack_backup_id, options=["-j", "4"]),
|
self.restore_node(backup_dir, 'node', node, backup_id=ptrack_backup_id, options=["-j", "4"]),
|
||||||
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(self.output), self.cmd))
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(self.output), self.cmd))
|
||||||
pgdata_restored = self.pgdata_content(node.data_dir)
|
pgdata_restored = self.pgdata_content(node.data_dir)
|
||||||
# self.compare_pgdata(pgdata, pgdata_restored)
|
|
||||||
node.start()
|
node.start()
|
||||||
while node.safe_psql("postgres", "select pg_is_in_recovery()") == 't\n':
|
while node.safe_psql("postgres", "select pg_is_in_recovery()") == 't\n':
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
ptrack_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap")
|
ptrack_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap")
|
||||||
self.assertEqual(ptrack_result, ptrack_result_new)
|
self.assertEqual(ptrack_result, ptrack_result_new)
|
||||||
|
|
||||||
|
if self.paranoia:
|
||||||
|
self.compare_pgdata(pgdata, pgdata_restored)
|
||||||
|
|
||||||
# Clean after yourself
|
# Clean after yourself
|
||||||
self.del_test_dir(module_name, fname)
|
self.del_test_dir(module_name, fname)
|
||||||
|
|
||||||
@@ -203,12 +205,15 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
self.restore_node(backup_dir, 'node', node, backup_id=ptrack_backup_id, options=["-j", "4", "--time={0}".format(ptrack_target_time)]),
|
self.restore_node(backup_dir, 'node', node, backup_id=ptrack_backup_id, options=["-j", "4", "--time={0}".format(ptrack_target_time)]),
|
||||||
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(self.output), self.cmd))
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(self.output), self.cmd))
|
||||||
pgdata_restored = self.pgdata_content(node.data_dir)
|
pgdata_restored = self.pgdata_content(node.data_dir)
|
||||||
# self.compare_pgdata(pgdata, pgdata_restored)
|
|
||||||
node.start()
|
node.start()
|
||||||
while node.safe_psql("postgres", "select pg_is_in_recovery()") == 't\n':
|
while node.safe_psql("postgres", "select pg_is_in_recovery()") == 't\n':
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
ptrack_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap")
|
ptrack_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap")
|
||||||
self.assertEqual(ptrack_result, ptrack_result_new)
|
self.assertEqual(ptrack_result, ptrack_result_new)
|
||||||
|
|
||||||
|
if self.paranoia:
|
||||||
|
self.compare_pgdata(pgdata, pgdata_restored)
|
||||||
|
|
||||||
node.cleanup()
|
node.cleanup()
|
||||||
|
|
||||||
# Clean after yourself
|
# Clean after yourself
|
||||||
@@ -401,8 +406,9 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
node_restored.cleanup()
|
node_restored.cleanup()
|
||||||
# COMPARE PHYSICAL CONTENT
|
# COMPARE PHYSICAL CONTENT
|
||||||
self.restore_node(backup_dir, 'node', node_restored, backup_id=backup_id, options=["-j", "4"])
|
self.restore_node(backup_dir, 'node', node_restored, backup_id=backup_id, options=["-j", "4"])
|
||||||
pgdata_new = self.pgdata_content(node_restored.data_dir)
|
pgdata_restored = self.pgdata_content(node_restored.data_dir)
|
||||||
# self.compare_pgdata(pgdata, pgdata_restored)
|
if self.paranoia:
|
||||||
|
self.compare_pgdata(pgdata, pgdata_restored)
|
||||||
|
|
||||||
# START RESTORED NODE
|
# START RESTORED NODE
|
||||||
node_restored.append_conf("postgresql.auto.conf", "port = {0}".format(node_restored.port))
|
node_restored.append_conf("postgresql.auto.conf", "port = {0}".format(node_restored.port))
|
||||||
@@ -424,8 +430,9 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
node_restored.start()
|
node_restored.start()
|
||||||
|
|
||||||
# COMPARE PHYSICAL CONTENT
|
# COMPARE PHYSICAL CONTENT
|
||||||
pgdata_new = self.pgdata_content(node_restored.data_dir)
|
pgdata_restored = self.pgdata_content(node_restored.data_dir)
|
||||||
# self.compare_pgdata(pgdata, pgdata_restored)
|
if self.paranoia:
|
||||||
|
self.compare_pgdata(pgdata, pgdata_restored)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
node_restored.safe_psql('db1', 'select 1')
|
node_restored.safe_psql('db1', 'select 1')
|
||||||
@@ -485,8 +492,7 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
])
|
])
|
||||||
|
|
||||||
# GET RESTORED PGDATA AND COMPARE
|
# GET RESTORED PGDATA AND COMPARE
|
||||||
pgdata_new = self.pgdata_content(node_restored.data_dir)
|
pgdata_restored = self.pgdata_content(node_restored.data_dir)
|
||||||
# self.compare_pgdata(pgdata, pgdata_new)
|
|
||||||
# START RESTORED NODE
|
# START RESTORED NODE
|
||||||
node_restored.append_conf('postgresql.auto.conf', 'port = {0}'.format(node_restored.port))
|
node_restored.append_conf('postgresql.auto.conf', 'port = {0}'.format(node_restored.port))
|
||||||
node_restored.start()
|
node_restored.start()
|
||||||
@@ -496,6 +502,8 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
result_new = node_restored.safe_psql("postgres", "select * from t_heap")
|
result_new = node_restored.safe_psql("postgres", "select * from t_heap")
|
||||||
|
|
||||||
self.assertEqual(result, result_new, 'lost some data after restore')
|
self.assertEqual(result, result_new, 'lost some data after restore')
|
||||||
|
if self.paranoia:
|
||||||
|
self.compare_pgdata(pgdata, pgdata_restored)
|
||||||
|
|
||||||
# Clean after yourself
|
# Clean after yourself
|
||||||
self.del_test_dir(module_name, fname)
|
self.del_test_dir(module_name, fname)
|
||||||
@@ -538,9 +546,10 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
"-T", "{0}={1}".format(self.get_tblspace_path(node,'somedata'), self.get_tblspace_path(node_restored,'somedata'))])
|
"-T", "{0}={1}".format(self.get_tblspace_path(node,'somedata'), self.get_tblspace_path(node_restored,'somedata'))])
|
||||||
|
|
||||||
# GET PHYSICAL CONTENT
|
# GET PHYSICAL CONTENT
|
||||||
pgdata_new = self.pgdata_content(node_restored.data_dir)
|
pgdata_restored = self.pgdata_content(node_restored.data_dir)
|
||||||
# COMPARE PHYSICAL CONTENT
|
# COMPARE PHYSICAL CONTENT
|
||||||
# self.compare_pgdata(pgdata, pgdata_restored)
|
if self.paranoia:
|
||||||
|
self.compare_pgdata(pgdata, pgdata_restored)
|
||||||
# START RESTORED NODE
|
# START RESTORED NODE
|
||||||
node_restored.start()
|
node_restored.start()
|
||||||
|
|
||||||
@@ -649,9 +658,8 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
"-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new)])
|
"-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new)])
|
||||||
result = node.safe_psql("postgres", "select * from t_heap")
|
result = node.safe_psql("postgres", "select * from t_heap")
|
||||||
|
|
||||||
pgdata_new = self.pgdata_content(restored_node.data_dir)
|
pgdata_restored = self.pgdata_content(restored_node.data_dir)
|
||||||
# COMPARE PHYSICAL CONTENT
|
|
||||||
# self.compare_pgdata(pgdata, pgdata_restored)
|
|
||||||
# START RESTORED NODE
|
# START RESTORED NODE
|
||||||
restored_node.append_conf("postgresql.auto.conf", "port = {0}".format(restored_node.port))
|
restored_node.append_conf("postgresql.auto.conf", "port = {0}".format(restored_node.port))
|
||||||
restored_node.start()
|
restored_node.start()
|
||||||
@@ -660,6 +668,11 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
|
|
||||||
result_new = restored_node.safe_psql("postgres", "select * from t_heap")
|
result_new = restored_node.safe_psql("postgres", "select * from t_heap")
|
||||||
self.assertEqual(result, result_new)
|
self.assertEqual(result, result_new)
|
||||||
|
|
||||||
|
# COMPARE PHYSICAL CONTENT
|
||||||
|
if self.paranoia:
|
||||||
|
self.compare_pgdata(pgdata, pgdata_restored)
|
||||||
|
|
||||||
restored_node.cleanup()
|
restored_node.cleanup()
|
||||||
shutil.rmtree(tblspc_path_new, ignore_errors=True)
|
shutil.rmtree(tblspc_path_new, ignore_errors=True)
|
||||||
|
|
||||||
@@ -675,9 +688,8 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
"-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new)])
|
"-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new)])
|
||||||
restored_node.append_conf("postgresql.auto.conf", "port = {0}".format(restored_node.port))
|
restored_node.append_conf("postgresql.auto.conf", "port = {0}".format(restored_node.port))
|
||||||
|
|
||||||
# COMPARE PHYSICAL CONTENT
|
# GET PHYSICAL CONTENT
|
||||||
pgdata_new = self.pgdata_content(restored_node.data_dir)
|
pgdata_restored = self.pgdata_content(restored_node.data_dir)
|
||||||
# self.compare_pgdata(pgdata, pgdata_restored)
|
|
||||||
|
|
||||||
# START RESTORED NODE
|
# START RESTORED NODE
|
||||||
restored_node.start()
|
restored_node.start()
|
||||||
@@ -687,13 +699,16 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
result_new = restored_node.safe_psql("postgres", "select * from t_heap")
|
result_new = restored_node.safe_psql("postgres", "select * from t_heap")
|
||||||
self.assertEqual(result, result_new)
|
self.assertEqual(result, result_new)
|
||||||
|
|
||||||
|
if self.paranoia:
|
||||||
|
# COMPARE PHYSICAL CONTENT
|
||||||
|
self.compare_pgdata(pgdata, pgdata_restored)
|
||||||
|
|
||||||
# Clean after yourself
|
# Clean after yourself
|
||||||
self.del_test_dir(module_name, fname)
|
self.del_test_dir(module_name, fname)
|
||||||
|
|
||||||
# @unittest.skip("skip")
|
# @unittest.skip("skip")
|
||||||
def test_relation_with_multiple_segments(self):
|
def test_relation_with_multiple_segments(self):
|
||||||
"""Make node, create table, alter table tablespace, take ptrack backup, move table from tablespace, take ptrack backup"""
|
"""Make node, create table, alter table tablespace, take ptrack backup, move table from tablespace, take ptrack backup"""
|
||||||
self.maxDiff = None
|
|
||||||
fname = self.id().split('.')[3]
|
fname = self.id().split('.')[3]
|
||||||
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
||||||
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
|
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
|
||||||
@@ -736,7 +751,6 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
|
|
||||||
# GET PHYSICAL CONTENT FROM NODE_RESTORED
|
# GET PHYSICAL CONTENT FROM NODE_RESTORED
|
||||||
pgdata_restored = self.pgdata_content(restored_node.data_dir)
|
pgdata_restored = self.pgdata_content(restored_node.data_dir)
|
||||||
# self.compare_pgdata(pgdata, pgdata_restored)
|
|
||||||
|
|
||||||
# START RESTORED NODE
|
# START RESTORED NODE
|
||||||
restored_node.append_conf("postgresql.auto.conf", "port = {0}".format(restored_node.port))
|
restored_node.append_conf("postgresql.auto.conf", "port = {0}".format(restored_node.port))
|
||||||
@@ -745,7 +759,12 @@ class PtrackBackupTest(ProbackupTest, unittest.TestCase):
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
result_new = restored_node.safe_psql("postgres", "select * from pgbench_accounts")
|
result_new = restored_node.safe_psql("postgres", "select * from pgbench_accounts")
|
||||||
|
|
||||||
|
# COMPARE RESTORED FILES
|
||||||
self.assertEqual(result, result_new)
|
self.assertEqual(result, result_new)
|
||||||
|
|
||||||
|
if self.paranoia:
|
||||||
|
self.compare_pgdata(pgdata, pgdata_restored)
|
||||||
|
|
||||||
# Clean after yourself
|
# Clean after yourself
|
||||||
self.del_test_dir(module_name, fname)
|
self.del_test_dir(module_name, fname)
|
||||||
|
@@ -76,7 +76,7 @@ class ValidateTest(ProbackupTest, unittest.TestCase):
|
|||||||
res = con.execute("INSERT INTO tbl0005 VALUES ('inserted') RETURNING (xmin)")
|
res = con.execute("INSERT INTO tbl0005 VALUES ('inserted') RETURNING (xmin)")
|
||||||
con.commit()
|
con.commit()
|
||||||
target_xid = res[0][0]
|
target_xid = res[0][0]
|
||||||
node.execute("postgres", "SELECT pg_switch_wal()")
|
self.switch_wal_segment(node)
|
||||||
|
|
||||||
self.assertIn("INFO: backup validation completed successfully",
|
self.assertIn("INFO: backup validation completed successfully",
|
||||||
self.validate_pb(backup_dir, 'node', options=["--xid={0}".format(target_xid)]),
|
self.validate_pb(backup_dir, 'node', options=["--xid={0}".format(target_xid)]),
|
||||||
|
Reference in New Issue
Block a user