Skip to content

Commit 618fa3f

Browse files
committed
[Issue #219] added test tests.init.InitTest.test_add_instance_idempotence
1 parent 0a2e5be commit 618fa3f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/init.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import unittest
33
from .helpers.ptrack_helpers import dir_files, ProbackupTest, ProbackupException
4+
import shutil
45

56

67
module_name = 'init'
@@ -104,3 +105,53 @@ def test_abs_path(self):
104105

105106
# Clean after yourself
106107
self.del_test_dir(module_name, fname)
108+
109+
# @unittest.skip("skip")
110+
# @unittest.expectedFailure
111+
def test_add_instance_idempotence(self):
112+
"""
113+
https://github.com/postgrespro/pg_probackup/issues/219
114+
"""
115+
fname = self.id().split(".")[3]
116+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
117+
node = self.make_simple_node(base_dir=os.path.join(module_name, fname, 'node'))
118+
self.init_pb(backup_dir)
119+
120+
self.add_instance(backup_dir, 'node', node)
121+
shutil.rmtree(os.path.join(backup_dir, 'backups', 'node'))
122+
123+
dir_backups = os.path.join(backup_dir, 'backups', 'node')
124+
dir_wal = os.path.join(backup_dir, 'wal', 'node')
125+
126+
try:
127+
self.add_instance(backup_dir, 'node', node)
128+
# we should die here because exception is what we expect to happen
129+
self.assertEqual(
130+
1, 0,
131+
"Expecting Error because page backup should not be possible "
132+
"\n Output: {0} \n CMD: {1}".format(
133+
repr(self.output), self.cmd))
134+
except ProbackupException as e:
135+
self.assertIn(
136+
"ERROR: Instance 'node' WAL archive directory already exists: ",
137+
e.message,
138+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
139+
repr(e.message), self.cmd))
140+
141+
try:
142+
self.add_instance(backup_dir, 'node', node)
143+
# we should die here because exception is what we expect to happen
144+
self.assertEqual(
145+
1, 0,
146+
"Expecting Error because page backup should not be possible "
147+
"\n Output: {0} \n CMD: {1}".format(
148+
repr(self.output), self.cmd))
149+
except ProbackupException as e:
150+
self.assertIn(
151+
"ERROR: Instance 'node' WAL archive directory already exists: ",
152+
e.message,
153+
"\n Unexpected Error Message: {0}\n CMD: {1}".format(
154+
repr(e.message), self.cmd))
155+
156+
# Clean after yourself
157+
self.del_test_dir(module_name, fname)

0 commit comments

Comments
 (0)