Skip to content

Commit 6b4f698

Browse files
committed
tests: more tests for backup locking
1 parent 2c08cb2 commit 6b4f698

File tree

2 files changed

+91
-3
lines changed

2 files changed

+91
-3
lines changed

tests/helpers/ptrack_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,7 @@ def _execute(self, cmd, running=True):
14321432
print(repr(line))
14331433
if line == '^done\n' or line.startswith('*stopped'):
14341434
break
1435-
if running and line.startswith('*running'):
1435+
if running and (line.startswith('*running') or line.startswith('^running')):
1436+
# if running and line.startswith('*running'):
14361437
break
14371438
return output

tests/locking.py

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class LockingTest(ProbackupTest, unittest.TestCase):
1212
# @unittest.skip("skip")
1313
# @unittest.expectedFailure
1414
def test_locking_simple_1(self):
15-
""""""
15+
"""
16+
make node, take full backup, stop it in the middle
17+
run validate, expect it to successfully executed,
18+
concurrect RUNNING backup with pid file and active process is legal
19+
"""
1620
fname = self.id().split('.')[3]
1721
node = self.make_simple_node(
1822
base_dir=os.path.join(module_name, fname, 'node'),
@@ -36,6 +40,12 @@ def test_locking_simple_1(self):
3640
if gdb.continue_execution_until_break(20) != 'breakpoint-hit':
3741
self.AssertTrue(False, 'Failed to hit breakpoint')
3842

43+
self.assertEqual(
44+
'OK', self.show_pb(backup_dir, 'node')[0]['status'])
45+
46+
self.assertEqual(
47+
'RUNNING', self.show_pb(backup_dir, 'node')[1]['status'])
48+
3949
self.validate_pb(backup_dir)
4050

4151
self.assertEqual(
@@ -48,7 +58,13 @@ def test_locking_simple_1(self):
4858
self.del_test_dir(module_name, fname)
4959

5060
def test_locking_simple_2(self):
51-
""""""
61+
"""
62+
make node, take full backup, stop it in the middle,
63+
kill process so no cleanup is done - pid file is in place,
64+
run validate, expect it to not successfully executed,
65+
RUNNING backup with pid file AND without active pid is legal,
66+
but his status must be changed to ERROR and pid file is deleted
67+
"""
5268
fname = self.id().split('.')[3]
5369
node = self.make_simple_node(
5470
base_dir=os.path.join(module_name, fname, 'node'),
@@ -72,7 +88,78 @@ def test_locking_simple_2(self):
7288
if gdb.continue_execution_until_break(20) != 'breakpoint-hit':
7389
self.AssertTrue(False, 'Failed to hit breakpoint')
7490

91+
gdb._execute('signal SIGKILL')
92+
gdb.continue_execution_until_running()
93+
94+
self.assertEqual(
95+
'OK', self.show_pb(backup_dir, 'node')[0]['status'])
96+
97+
self.assertEqual(
98+
'RUNNING', self.show_pb(backup_dir, 'node')[1]['status'])
99+
75100
self.validate_pb(backup_dir)
76101

102+
self.assertEqual(
103+
'OK', self.show_pb(backup_dir, 'node')[0]['status'])
104+
105+
self.assertEqual(
106+
'ERROR', self.show_pb(backup_dir, 'node')[1]['status'])
107+
108+
# Clean after yourself
109+
self.del_test_dir(module_name, fname)
110+
111+
def test_locking_simple_3(self):
112+
"""
113+
make node, take full backup, stop it in the middle,
114+
terminate process, delete pid file,
115+
run validate, expect it to not successfully executed,
116+
RUNNING backup without pid file AND without active pid is legal,
117+
his status must be changed to ERROR
118+
"""
119+
fname = self.id().split('.')[3]
120+
node = self.make_simple_node(
121+
base_dir=os.path.join(module_name, fname, 'node'),
122+
initdb_params=['--data-checksums'],
123+
pg_options={'wal_level': 'replica'})
124+
125+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
126+
self.init_pb(backup_dir)
127+
self.add_instance(backup_dir, 'node', node)
128+
self.set_archiving(backup_dir, 'node', node)
129+
node.slow_start()
130+
131+
self.backup_node(backup_dir, 'node', node)
132+
133+
gdb = self.backup_node(
134+
backup_dir, 'node', node, gdb=True)
135+
136+
gdb.set_breakpoint('copy_file')
137+
gdb.run_until_break()
138+
139+
if gdb.continue_execution_until_break(20) != 'breakpoint-hit':
140+
self.AssertTrue(False, 'Failed to hit breakpoint')
141+
142+
gdb._execute('signal SIGKILL')
143+
gdb.continue_execution_until_running()
144+
145+
self.assertEqual(
146+
'OK', self.show_pb(backup_dir, 'node')[0]['status'])
147+
148+
self.assertEqual(
149+
'RUNNING', self.show_pb(backup_dir, 'node')[1]['status'])
150+
151+
backup_id = self.show_pb(backup_dir, 'node')[1]['id']
152+
153+
os.remove(
154+
os.path.join(backup_dir, 'backups', 'node', backup_id, 'backup.pid'))
155+
156+
self.validate_pb(backup_dir)
157+
158+
self.assertEqual(
159+
'OK', self.show_pb(backup_dir, 'node')[0]['status'])
160+
161+
self.assertEqual(
162+
'ERROR', self.show_pb(backup_dir, 'node')[1]['status'])
163+
77164
# Clean after yourself
78165
self.del_test_dir(module_name, fname)

0 commit comments

Comments
 (0)