1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-01-08 13:44:32 +02:00

tests: minor fixes

This commit is contained in:
Grigory Smolkin 2019-10-08 14:33:52 +03:00
parent 9edb2e3498
commit 0deff06912
7 changed files with 65 additions and 90 deletions

View File

@ -58,9 +58,7 @@ class ArchiveTest(ProbackupTest, unittest.TestCase):
node.cleanup() node.cleanup()
# Restore Database # Restore Database
self.restore_node( self.restore_node(backup_dir, 'node', node)
backup_dir, 'node', node,
options=["--recovery-target-action=promote"])
node.slow_start() node.slow_start()
self.assertEqual( self.assertEqual(
@ -1590,11 +1588,9 @@ class ArchiveTest(ProbackupTest, unittest.TestCase):
self.restore_node( self.restore_node(
backup_dir, 'node', node, backup_dir, 'node', node,
options=[ options=[
'--recovery-target-action=promote',
'--archive-host=localhost', '--archive-host=localhost',
'--archive-port=22', '--archive-port=22',
'--archive-user={0}'.format(self.user) '--archive-user={0}'.format(self.user)])
])
with open(recovery_conf, 'r') as f: with open(recovery_conf, 'r') as f:
recovery_content = f.read() recovery_content = f.read()

View File

@ -20,8 +20,8 @@ class CompatibilityTest(ProbackupTest, unittest.TestCase):
set_replication=True, set_replication=True,
initdb_params=['--data-checksums'], initdb_params=['--data-checksums'],
pg_options={ pg_options={
'autovacuum': 'off'} 'autovacuum': 'off'})
)
self.init_pb(backup_dir, old_binary=True) self.init_pb(backup_dir, old_binary=True)
self.show_pb(backup_dir) self.show_pb(backup_dir)
@ -51,8 +51,7 @@ class CompatibilityTest(ProbackupTest, unittest.TestCase):
node_restored.cleanup() node_restored.cleanup()
self.restore_node( self.restore_node(
backup_dir, 'node', node_restored, backup_dir, 'node', node_restored, options=["-j", "4"])
options=["-j", "4", "--recovery-target-action=promote"])
if self.paranoia: if self.paranoia:
pgdata_restored = self.pgdata_content(node_restored.data_dir) pgdata_restored = self.pgdata_content(node_restored.data_dir)
@ -76,8 +75,7 @@ class CompatibilityTest(ProbackupTest, unittest.TestCase):
node_restored.cleanup() node_restored.cleanup()
self.restore_node( self.restore_node(
backup_dir, 'node', node_restored, backup_dir, 'node', node_restored, options=["-j", "4"])
options=["-j", "4", "--recovery-target-action=promote"])
if self.paranoia: if self.paranoia:
pgdata_restored = self.pgdata_content(node_restored.data_dir) pgdata_restored = self.pgdata_content(node_restored.data_dir)
@ -101,8 +99,7 @@ class CompatibilityTest(ProbackupTest, unittest.TestCase):
node_restored.cleanup() node_restored.cleanup()
self.restore_node( self.restore_node(
backup_dir, 'node', node_restored, backup_dir, 'node', node_restored, options=["-j", "4"])
options=["-j", "4", "--recovery-target-action=promote"])
if self.paranoia: if self.paranoia:
pgdata_restored = self.pgdata_content(node_restored.data_dir) pgdata_restored = self.pgdata_content(node_restored.data_dir)
@ -122,8 +119,8 @@ class CompatibilityTest(ProbackupTest, unittest.TestCase):
set_replication=True, set_replication=True,
initdb_params=['--data-checksums'], initdb_params=['--data-checksums'],
pg_options={ pg_options={
'autovacuum': 'off'} 'autovacuum': 'off'})
)
self.init_pb(backup_dir, old_binary=True) self.init_pb(backup_dir, old_binary=True)
self.show_pb(backup_dir) self.show_pb(backup_dir)
@ -153,8 +150,7 @@ class CompatibilityTest(ProbackupTest, unittest.TestCase):
node_restored.cleanup() node_restored.cleanup()
self.restore_node( self.restore_node(
backup_dir, 'node', node_restored, backup_dir, 'node', node_restored, options=["-j", "4"])
options=["-j", "4", "--recovery-target-action=promote"])
if self.paranoia: if self.paranoia:
pgdata_restored = self.pgdata_content(node_restored.data_dir) pgdata_restored = self.pgdata_content(node_restored.data_dir)
@ -178,8 +174,7 @@ class CompatibilityTest(ProbackupTest, unittest.TestCase):
node_restored.cleanup() node_restored.cleanup()
self.restore_node( self.restore_node(
backup_dir, 'node', node_restored, backup_dir, 'node', node_restored, options=["-j", "4"])
options=["-j", "4", "--recovery-target-action=promote"])
if self.paranoia: if self.paranoia:
pgdata_restored = self.pgdata_content(node_restored.data_dir) pgdata_restored = self.pgdata_content(node_restored.data_dir)
@ -203,8 +198,7 @@ class CompatibilityTest(ProbackupTest, unittest.TestCase):
node_restored.cleanup() node_restored.cleanup()
self.restore_node( self.restore_node(
backup_dir, 'node', node_restored, backup_dir, 'node', node_restored, options=["-j", "4"])
options=["-j", "4", "--recovery-target-action=promote"])
if self.paranoia: if self.paranoia:
pgdata_restored = self.pgdata_content(node_restored.data_dir) pgdata_restored = self.pgdata_content(node_restored.data_dir)

View File

@ -465,9 +465,9 @@ class DeltaTest(ProbackupTest, unittest.TestCase):
tblspc_path_new = self.get_tblspace_path( tblspc_path_new = self.get_tblspace_path(
restored_node, 'somedata_restored') restored_node, 'somedata_restored')
self.restore_node(backup_dir, 'node', restored_node, options=[ self.restore_node(
"-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new), backup_dir, 'node', restored_node, options=[
"--recovery-target-action=promote"]) "-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new)])
# 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)
@ -835,8 +835,8 @@ class DeltaTest(ProbackupTest, unittest.TestCase):
"postgres", "postgres",
"create table t_heap tablespace somedata as select i as id," "create table t_heap tablespace somedata as select i as id,"
" md5(i::text) as text, md5(i::text)::tsvector as tsvector" " md5(i::text) as text, md5(i::text)::tsvector as tsvector"
" from generate_series(0,100) i" " from generate_series(0,100) i")
)
# FULL backup # FULL backup
self.backup_node(backup_dir, 'node', node, options=["--stream"]) self.backup_node(backup_dir, 'node', node, options=["--stream"])
@ -844,8 +844,7 @@ class DeltaTest(ProbackupTest, unittest.TestCase):
self.create_tblspace_in_node(node, 'somedata_new') self.create_tblspace_in_node(node, 'somedata_new')
node.safe_psql( node.safe_psql(
"postgres", "postgres",
"alter table t_heap set tablespace somedata_new" "alter table t_heap set tablespace somedata_new")
)
# DELTA BACKUP # DELTA BACKUP
result = node.safe_psql( result = node.safe_psql(
@ -853,15 +852,14 @@ class DeltaTest(ProbackupTest, unittest.TestCase):
self.backup_node( self.backup_node(
backup_dir, 'node', node, backup_dir, 'node', node,
backup_type='delta', backup_type='delta',
options=["--stream"] options=["--stream"])
)
if self.paranoia: if self.paranoia:
pgdata = self.pgdata_content(node.data_dir) pgdata = self.pgdata_content(node.data_dir)
# RESTORE # RESTORE
node_restored = self.make_simple_node( node_restored = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node_restored') base_dir=os.path.join(module_name, fname, 'node_restored'))
)
node_restored.cleanup() node_restored.cleanup()
self.restore_node( self.restore_node(
@ -875,8 +873,7 @@ class DeltaTest(ProbackupTest, unittest.TestCase):
"-T", "{0}={1}".format( "-T", "{0}={1}".format(
self.get_tblspace_path(node, 'somedata_new'), self.get_tblspace_path(node, 'somedata_new'),
self.get_tblspace_path(node_restored, 'somedata_new') self.get_tblspace_path(node_restored, 'somedata_new')
), )
"--recovery-target-action=promote"
] ]
) )
@ -1275,7 +1272,7 @@ class DeltaTest(ProbackupTest, unittest.TestCase):
content = f.read() content = f.read()
self.assertIn( self.assertIn(
"VERBOSE: File: {0} blknum 1, empty page".format(file), 'VERBOSE: File: "{0}" blknum 1, empty page'.format(file),
content) content)
self.assertNotIn( self.assertNotIn(
"Skipping blknum 1 in file: {0}".format(file), "Skipping blknum 1 in file: {0}".format(file),

View File

@ -642,9 +642,8 @@ class MergeTest(ProbackupTest, unittest.TestCase):
initdb_params=['--data-checksums'], initdb_params=['--data-checksums'],
pg_options={ pg_options={
'checkpoint_timeout': '300s', 'checkpoint_timeout': '300s',
'autovacuum': 'off' 'autovacuum': 'off'})
}
)
node_restored = self.make_simple_node( node_restored = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node_restored')) base_dir=os.path.join(module_name, fname, 'node_restored'))
@ -694,8 +693,7 @@ class MergeTest(ProbackupTest, unittest.TestCase):
backup_dir, 'node', node_restored, backup_dir, 'node', node_restored,
options=[ options=[
"-j", "4", "-j", "4",
"-T", "{0}={1}".format(old_tablespace, new_tablespace), "-T", "{0}={1}".format(old_tablespace, new_tablespace)])
"--recovery-target-action=promote"])
# Physical comparison # Physical comparison
if self.paranoia: if self.paranoia:
@ -735,9 +733,8 @@ class MergeTest(ProbackupTest, unittest.TestCase):
initdb_params=['--data-checksums'], initdb_params=['--data-checksums'],
pg_options={ pg_options={
'checkpoint_timeout': '300s', 'checkpoint_timeout': '300s',
'autovacuum': 'off' 'autovacuum': 'off'})
}
)
node_restored = self.make_simple_node( node_restored = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node_restored')) base_dir=os.path.join(module_name, fname, 'node_restored'))
@ -787,8 +784,7 @@ class MergeTest(ProbackupTest, unittest.TestCase):
backup_dir, 'node', node_restored, backup_dir, 'node', node_restored,
options=[ options=[
"-j", "4", "-j", "4",
"-T", "{0}={1}".format(old_tablespace, new_tablespace), "-T", "{0}={1}".format(old_tablespace, new_tablespace)])
"--recovery-target-action=promote"])
# Physical comparison # Physical comparison
if self.paranoia: if self.paranoia:

View File

@ -28,9 +28,8 @@ class PageBackupTest(ProbackupTest, unittest.TestCase):
initdb_params=['--data-checksums'], initdb_params=['--data-checksums'],
pg_options={ pg_options={
'checkpoint_timeout': '300s', 'checkpoint_timeout': '300s',
'autovacuum': 'off' 'autovacuum': 'off'})
}
)
node_restored = self.make_simple_node( node_restored = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node_restored')) base_dir=os.path.join(module_name, fname, 'node_restored'))
@ -78,8 +77,7 @@ class PageBackupTest(ProbackupTest, unittest.TestCase):
backup_dir, 'node', node_restored, backup_dir, 'node', node_restored,
options=[ options=[
"-j", "4", "-j", "4",
"-T", "{0}={1}".format(old_tablespace, new_tablespace), "-T", "{0}={1}".format(old_tablespace, new_tablespace)])
"--recovery-target-action=promote"])
# Physical comparison # Physical comparison
if self.paranoia: if self.paranoia:
@ -302,9 +300,7 @@ class PageBackupTest(ProbackupTest, unittest.TestCase):
'shared_buffers': '1GB', 'shared_buffers': '1GB',
'maintenance_work_mem': '1GB', 'maintenance_work_mem': '1GB',
'autovacuum': 'off', 'autovacuum': 'off',
'full_page_writes': 'off' 'full_page_writes': 'off'})
}
)
self.init_pb(backup_dir) self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node) self.add_instance(backup_dir, 'node', node)
@ -343,7 +339,6 @@ class PageBackupTest(ProbackupTest, unittest.TestCase):
backup_dir, 'node', restored_node, backup_dir, 'node', restored_node,
options=[ options=[
"-j", "4", "-j", "4",
"--recovery-target-action=promote",
"-T", "{0}={1}".format(tblspc_path, tblspc_path_new)]) "-T", "{0}={1}".format(tblspc_path, tblspc_path_new)])
# GET PHYSICAL CONTENT FROM NODE_RESTORED # GET PHYSICAL CONTENT FROM NODE_RESTORED
@ -958,15 +953,14 @@ class PageBackupTest(ProbackupTest, unittest.TestCase):
"Output: {0} \n CMD: {1}".format( "Output: {0} \n CMD: {1}".format(
self.output, self.cmd)) self.output, self.cmd))
except ProbackupException as e: except ProbackupException as e:
self.assertTrue( self.assertIn('INFO: Wait for WAL segment', e.message)
'INFO: Wait for LSN' in e.message and self.assertIn('to be archived', e.message)
'in archived WAL segment' in e.message and self.assertIn('Could not read WAL record at', e.message)
'Could not read WAL record at' in e.message and self.assertIn('WAL file is from different database system: '
'WAL file is from different database system: WAL file database system identifier is' in e.message and 'WAL file database system identifier is', e.message)
'pg_control database system identifier is' in e.message and self.assertIn('pg_control database system identifier is', e.message)
'Possible WAL corruption. Error has occured during reading WAL segment' in e.message, self.assertIn('Possible WAL corruption. Error has occured '
'\n Unexpected Error Message: {0}\n CMD: {1}'.format( 'during reading WAL segment', e.message)
repr(e.message), self.cmd))
self.assertEqual( self.assertEqual(
'ERROR', 'ERROR',

View File

@ -47,8 +47,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase):
self.assertIn( self.assertIn(
"INFO: Restore of backup {0} completed.".format(backup_id), "INFO: Restore of backup {0} completed.".format(backup_id),
self.restore_node( self.restore_node(
backup_dir, 'node', node, backup_dir, 'node', node, options=["-j", "4"]),
options=["-j", "4", "--recovery-target-action=promote"]),
'\n Unexpected Error Message: {0}\n CMD: {1}'.format( '\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(self.output), self.cmd)) repr(self.output), self.cmd))
@ -98,8 +97,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase):
self.assertIn( self.assertIn(
"INFO: Restore of backup {0} completed.".format(backup_id), "INFO: Restore of backup {0} completed.".format(backup_id),
self.restore_node( self.restore_node(
backup_dir, 'node', node, backup_dir, 'node', node, options=["-j", "4"]),
options=["-j", "4", "--recovery-target-action=promote"]),
'\n Unexpected Error Message: {0}\n CMD: {1}'.format( '\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(self.output), self.cmd)) repr(self.output), self.cmd))
@ -139,8 +137,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase):
self.assertIn( self.assertIn(
"INFO: Restore of backup {0} completed.".format(backup_id), "INFO: Restore of backup {0} completed.".format(backup_id),
self.restore_node( self.restore_node(
backup_dir, 'node', node, backup_dir, 'node', node, options=["-j", "4"]),
options=["-j", "4", "--recovery-target-action=promote"]),
'\n Unexpected Error Message: {0}\n CMD: {1}'.format( '\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(self.output), self.cmd)) repr(self.output), self.cmd))
@ -162,8 +159,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase):
self.restore_node( self.restore_node(
backup_dir, 'node', node, backup_dir, 'node', node,
options=[ options=[
"-j", "4", "--timeline={0}".format(target_tli), "-j", "4", "--timeline={0}".format(target_tli)]
"--recovery-target-action=promote"]
), ),
'\n Unexpected Error Message: {0}\n CMD: {1}'.format( '\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(self.output), self.cmd)) repr(self.output), self.cmd))
@ -883,8 +879,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase):
self.restore_node( self.restore_node(
backup_dir, 'node', node, backup_dir, 'node', node,
options=[ options=[
"-T", "%s=%s" % (tblspc_path, tblspc_path_new), "-T", "%s=%s" % (tblspc_path, tblspc_path_new)]
"--recovery-target-action=promote"]
), ),
'\n Unexpected Error Message: {0}\n CMD: {1}'.format( '\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(self.output), self.cmd)) repr(self.output), self.cmd))
@ -915,8 +910,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase):
self.restore_node( self.restore_node(
backup_dir, 'node', node, backup_dir, 'node', node,
options=[ options=[
"-T", "%s=%s" % (tblspc_path_new, tblspc_path_page), "-T", "%s=%s" % (tblspc_path_new, tblspc_path_page)]),
"--recovery-target-action=promote"]),
'\n Unexpected Error Message: {0}\n CMD: {1}'.format( '\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(self.output), self.cmd)) repr(self.output), self.cmd))
@ -991,8 +985,7 @@ class RestoreTest(ProbackupTest, unittest.TestCase):
self.restore_node( self.restore_node(
backup_dir, 'node', node, backup_dir, 'node', node,
options=[ options=[
"-T", "%s=%s" % (tblspc_path, tblspc_path_new), "-T", "%s=%s" % (tblspc_path, tblspc_path_new)]),
"--recovery-target-action=promote"]),
'\n Unexpected Error Message: {0}\n CMD: {1}'.format( '\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(self.output), self.cmd)) repr(self.output), self.cmd))
node.slow_start() node.slow_start()
@ -1804,25 +1797,23 @@ class RestoreTest(ProbackupTest, unittest.TestCase):
recovery_conf = os.path.join(node.data_dir, 'recovery.conf') recovery_conf = os.path.join(node.data_dir, 'recovery.conf')
# restore page backup # restore delta backup
node.cleanup() node.cleanup()
self.restore_node( self.restore_node(
backup_dir, 'node', node, options=['--immediate']) backup_dir, 'node', node, options=['--immediate'])
# For stream backup with immediate recovery target there is no need to self.assertTrue(
# create recovery.conf. Is it wise? os.path.isfile(recovery_conf),
self.assertFalse( "File {0} do not exists".format(recovery_conf))
os.path.isfile(recovery_conf))
# restore page backup # restore delta backup
node.cleanup() node.cleanup()
self.restore_node( self.restore_node(
backup_dir, 'node', node, options=['--recovery-target=immediate']) backup_dir, 'node', node, options=['--recovery-target=immediate'])
# For stream backup with immediate recovery target there is no need to self.assertTrue(
# create recovery.conf. Is it wise? os.path.isfile(recovery_conf),
self.assertFalse( "File {0} do not exists".format(recovery_conf))
os.path.isfile(recovery_conf))
# Clean after yourself # Clean after yourself
self.del_test_dir(module_name, fname) self.del_test_dir(module_name, fname)

View File

@ -60,8 +60,15 @@ class RetentionTest(ProbackupTest, unittest.TestCase):
for wal_name in os.listdir(os.path.join(backup_dir, 'wal', 'node')): for wal_name in os.listdir(os.path.join(backup_dir, 'wal', 'node')):
if not wal_name.endswith(".backup"): if not wal_name.endswith(".backup"):
self.assertTrue(wal_name[8:] >= min_wal)
self.assertTrue(wal_name[8:] <= max_wal) if self.archive_compress:
wal_name = wal_name[-19:]
wal_name = wal_name[:-3]
else:
wal_name = wal_name[-16:]
self.assertTrue(wal_name >= min_wal)
self.assertTrue(wal_name <= max_wal)
# Clean after yourself # Clean after yourself
self.del_test_dir(module_name, fname) self.del_test_dir(module_name, fname)