8000 [PBCKP-304] cfs tests moved back to build · postgrespro/pg_probackup@03f210b · GitHub
[go: up one dir, main page]

Skip to content

Commit 03f210b

Browse files
author
Ivan Lazarev
committed
[PBCKP-304] cfs tests moved back to build
1 parent ba6b240 commit 03f210b

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

tests/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def load_tests(loader, tests, pattern):
3535
suite.addTests(loader.loadTestsFromModule(compatibility))
3636
suite.addTests(loader.loadTestsFromModule(checkdb))
3737
suite.addTests(loader.loadTestsFromModule(config))
38-
# suite.addTests(loader.loadTestsFromModule(cfs_backup))
39-
# suite.addTests(loader.loadTestsFromModule(cfs_restore))
40-
# suite.addTests(loader.loadTestsFromModule(cfs_validate_backup))
38+
suite.addTests(loader.loadTestsFromModule(cfs_backup))
39+
suite.addTests(loader.loadTestsFromModule(cfs_restore))
40+
suite.addTests(loader.loadTestsFromModule(cfs_validate_backup))
4141
suite.addTests(loader.loadTestsFromModule(compression))
4242
suite.addTests(loader.loadTestsFromModule(delete))
4343
suite.addTests(loader.loadTestsFromModule(delta))

tests/cfs_backup.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import shutil
55

66
from .helpers.cfs_help 10000 ers import find_by_extensions, find_by_name, find_by_pattern, corrupt_file
7-
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
7+
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException, is_test_result_ok
88

99
module_name = 'cfs_backup'
1010
tblspace_name = 'cfs_tblspace'
@@ -1159,10 +1159,12 @@ def test_broken_file_pg_compression_into_tablespace_dir(self):
11591159
)
11601160

11611161
# # --- End ---#
1162-
# @unittest.skipUnless(ProbackupTest.enterprise, 'skip')
1163-
# def tearDown(self):
1164-
# self.node.cleanup()
1165-
# self.del_test_dir(module_name, self.fname)
1162+
@unittest.skipUnless(ProbackupTest.enterprise, 'skip')
1163+
def tearDown(self):
1164+
module_name = self.id().split('.')[1]
1165+
fname = self.id().split('.')[3]
1166+
if is_test_result_ok(self):
1167+
self.del_test_dir(module_name, fname)
11661168

11671169

11681170
#class CfsBackupEncTest(CfsBackupNoEncTest):

tests/cfs_restore.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import shutil
1414

1515
from .helpers.cfs_helpers import find_by_name
16-
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
16+
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException, is_test_result_ok
1717

1818

1919
module_name = 'cfs_restore'
@@ -60,9 +60,12 @@ def setUp(self):
6060
def add_data_in_cluster(self):
6161
pass
6262

63+
@unittest.skipUnless(ProbackupTest.enterprise, 'skip')
6364
def tearDown(self):
64-
self.node.cleanup()
65-
self.del_test_dir(module_name, self.fname)
65+
module_name = self.id().split('.')[1]
66+
fname = self.id().split('.')[3]
67+
if is_test_result_ok(self):
68+
self.del_test_dir(module_name, fname)
6669

6770

6871
class CfsRestoreNoencEmptyTablespaceTest(CfsRestoreBase):

tests/helpers/ptrack_helpers.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# you need os for unittest to work
22
import os
33
import gc
4+
import unittest
45
from sys import exit, argv, version_info
56
import subprocess
67
import shutil
@@ -172,6 +173,30 @@ def slow_start(self, replica=False):
172173

173174
sleep(0.5)
174175

176+
177+
def is_test_result_ok(test_case):
178+
# sources of solution:
179+
# 1. python versions 2.7 - 3.10, verified on 3.10, 3.7, 2.7, taken from:
180+
# https://tousu.in/qa/?qa=555402/unit-testing-getting-pythons-unittest-results-in-a-teardown-method&show=555403#a555403
181+
#
182+
# 2. python versions 3.11+ mixin, verified on 3.11, taken from: https://stackoverflow.com/a/39606065
183+
184+
if hasattr(test_case, '_outcome'): # Python 3.4+
185+
if hasattr(test_case._outcome, 'errors'):
186+
# Python 3.4 - 3.10 (These two methods have no side effects)
187+
result = test_case.defaultTestResult() # These two methods have no side effects
188+
test_case._feedErrorsToResult(result, test_case._outcome.errors)
189+
else:
190+
# Python 3.11+
191+
result = test_case._outcome.result
192+
else: # Python 2.7, 3.0-3.3
193+
result = getattr(test_case, '_outcomeForDoCleanups', test_case._resultForDoCleanups)
194+
195+
ok = all(test != test_case for test, text in result.errors + result.failures)
196+
197+
return ok
198+
199+
175200
class ProbackupTest(object):
176201
# Class attributes
177202
enterprise = is_enterprise()

0 commit comments

Comments
 (0)
0