|
1 | 1 | import os
|
2 | 2 | import unittest
|
3 | 3 | from .helpers.ptrack_helpers import dir_files, ProbackupTest, ProbackupException
|
| 4 | +import shutil |
4 | 5 |
|
5 | 6 |
|
6 | 7 | module_name = 'init'
|
@@ -104,3 +105,53 @@ def test_abs_path(self):
|
104 | 105 |
|
105 | 106 | # Clean after yourself
|
106 | 107 | 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