Skip to content

Commit

Permalink
[Issue #313] added test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmolk committed Jun 16, 2021
1 parent d1106e5 commit 6e8e948
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/helpers/ptrack_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,9 @@ def stopped_in_breakpoint(self):
return True
return False

def quit(self):
self.proc.terminate()

# use for breakpoint, run, continue
def _execute(self, cmd, running=True):
output = []
Expand Down
66 changes: 65 additions & 1 deletion tests/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import shutil
import json
from shutil import copyfile
from testgres import QueryException
from testgres import QueryException, StartNodeException
from stat import S_ISDIR


module_name = 'restore'
Expand Down Expand Up @@ -3856,3 +3857,66 @@ def test_concurrent_restore(self):

# Clean after yourself
self.del_test_dir(module_name, fname)

# @unittest.skip("skip")
def test_restore_issue_313(self):
"""
Check that partially restored PostgreSQL instance cannot be started
"""
fname = self.id().split('.')[3]
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
node = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node'),
set_replication=True,
initdb_params=['--data-checksums'])

self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node)
self.set_archiving(backup_dir, 'node', node)
node.slow_start()

# FULL backup
backup_id = self.backup_node(backup_dir, 'node', node)
node.cleanup()

count = 0
filelist = self.get_backup_filelist(backup_dir, 'node', backup_id)
for file in filelist:
# count only nondata files
if int(filelist[file]['is_datafile']) == 0 and int(filelist[file]['size']) > 0:
count += 1

node_restored = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'node_restored'))
node_restored.cleanup()
self.restore_node(backup_dir, 'node', node_restored)

gdb = self.restore_node(backup_dir, 'node', node, gdb=True, options=['--progress'])
gdb.verbose = False
gdb.set_breakpoint('restore_non_data_file')
gdb.run_until_break()
gdb.continue_execution_until_break(count - 2)
gdb.quit()

# emulate the user or HA taking care of PG configuration
for fname in os.listdir(node_restored.data_dir):
if fname.endswith('.conf'):
os.rename(
os.path.join(node_restored.data_dir, fname),
os.path.join(node.data_dir, fname))

try:
node.slow_start()
# we should die here because exception is what we expect to happen
self.assertEqual(
1, 0,
"Expecting Error because backup is not fully restored")
except StartNodeException as e:
self.assertIn(
'Cannot start node',
e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(e.message), self.cmd))

# Clean after yourself
self.del_test_dir(module_name, fname)

0 comments on commit 6e8e948

Please sign in to comment.