@@ -12,7 +12,11 @@ class LockingTest(ProbackupTest, unittest.TestCase):
12
12
# @unittest.skip("skip")
13
13
# @unittest.expectedFailure
14
14
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
+ """
16
20
fname = self .id ().split ('.' )[3 ]
17
21
node = self .make_simple_node (
18
22
base_dir = os .path .join (module_name , fname , 'node' ),
@@ -36,6 +40,12 @@ def test_locking_simple_1(self):
36
40
if gdb .continue_execution_until_break (20 ) != 'breakpoint-hit' :
37
41
self .AssertTrue (False , 'Failed to hit breakpoint' )
38
42
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
+
39
49
self .validate_pb (backup_dir )
40
50
41
51
self .assertEqual (
@@ -48,7 +58,13 @@ def test_locking_simple_1(self):
48
58
self .del_test_dir (module_name , fname )
49
59
50
60
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
+ """
52
68
fname = self .id ().split ('.' )[3 ]
53
69
node = self .make_simple_node (
54
70
base_dir = os .path .join (module_name , fname , 'node' ),
@@ -72,7 +88,78 @@ def test_locking_simple_2(self):
72
88
if gdb .continue_execution_until_break (20 ) != 'breakpoint-hit' :
73
89
self .AssertTrue (False , 'Failed to hit breakpoint' )
74
90
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
+
75
100
self .validate_pb (backup_dir )
76
101
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
+
77
164
# Clean after yourself
78
165
self .del_test_dir (module_name , fname )
0 commit comments