Skip to content

Commit 6e8e948

Browse files
committed
[Issue #313] added test coverage
1 parent d1106e5 commit 6e8e948

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

tests/helpers/ptrack_helpers.py

+3
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,9 @@ def stopped_in_breakpoint(self):
19501950
return True
19511951
return False
19521952

1953+
def quit(self):
1954+
self.proc.terminate()
1955+
19531956
# use for breakpoint, run, continue
19541957
def _execute(self, cmd, running=True):
19551958
output = []

tests/restore.py

+65-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import shutil
1010
import json
1111
from shutil import copyfile
12-
from testgres import QueryException
12+
from testgres import QueryException, StartNodeException
13+
from stat import S_ISDIR
1314

1415

1516
module_name = 'restore'
@@ -3856,3 +3857,66 @@ def test_concurrent_restore(self):
38563857

38573858
# Clean after yourself
38583859
self.del_test_dir(module_name, fname)
3860+
3861+
# @unittest.skip("skip")
3862+
def test_restore_issue_313(self):
3863+
"""
3864+
Check that partially restored PostgreSQL instance cannot be started
3865+
"""
3866+
fname = self.id().split('.')[3]
3867+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
3868+
node = self.make_simple_node(
3869+
base_dir=os.path.join(module_name, fname, 'node'),
3870+
set_replication=True,
3871+
initdb_params=['--data-checksums'])
3872+
3873+
self.init_pb(backup_dir)
3874+
self.add_instance(backup_dir, 'node', node)
3875+
self.set_archiving(backup_dir, 'node', node)
3876+
node.slow_start()
3877+
3878+
# FULL backup
3879+
backup_id = self.backup_node(backup_dir, 'node', node)
3880+
node.cleanup()
3881+
3882+
count = 0
3883+
filelist = self.get_backup_filelist(backup_dir, 'node', backup_id)
3884+
for file in filelist:
3885+
# count only nondata files
3886+
if int(filelist[file]['is_datafile']) == 0 and int(filelist[file]['size']) > 0:
3887+
count += 1
3888+
3889+
node_restored = self.make_simple_node(
3890+
base_dir=os.path.join(module_name, fname, 'node_restored'))
3891+
node_restored.cleanup()
3892+
self.restore_node(backup_dir, 'node', node_restored)
3893+
3894+
gdb = self.restore_node(backup_dir, 'node', node, gdb=True, options=['--progress'])
3895+
gdb.verbose = False
3896+
gdb.set_breakpoint('restore_non_data_file')
3897+
gdb.run_until_break()
3898+
gdb.continue_execution_until_break(count - 2)
3899+
gdb.quit()
3900+
3901+
# emulate the user or HA taking care of PG configuration
3902+
for fname in os.listdir(node_restored.data_dir):
3903+
if fname.endswith('.conf'):
3904+
os.rename(
3905+
os.path.join(node_restored.data_dir, fname),
3906+
os.path.join(node.data_dir, fname))
3907+
3908+
try:
3909+
node.slow_start()
3910+
# we should die here because exception is what we expect to happen
3911+
self.assertEqual(
3912+
1, 0,
3913+
"Expecting Error because backup is not fully restored")
3914+
except StartNodeException as e:
3915+
self.assertIn(
3916+
'Cannot start node',
3917+
e.message,
3918+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
3919+
repr(e.message), self.cmd))
3920+
3921+
# Clean after yourself
3922+
self.del_test_dir(module_name, fname)

0 commit comments

Comments
 (0)