summaryrefslogtreecommitdiffstats
path: root/SCons/Taskmaster
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2022-12-03 22:20:12 (GMT)
committerWilliam Deegan <bill@baddogconsulting.com>2022-12-03 22:20:12 (GMT)
commit3f4a001be6f517fafdbd75e81b0a0011cdf5ab7e (patch)
tree41adb96bbdf56d64189bc047319399a46f3555f4 /SCons/Taskmaster
parent84b32443baaa272f62ae6ed9fe3427ba57a5e960 (diff)
downloadSCons-3f4a001be6f517fafdbd75e81b0a0011cdf5ab7e.zip
SCons-3f4a001be6f517fafdbd75e81b0a0011cdf5ab7e.tar.gz
SCons-3f4a001be6f517fafdbd75e81b0a0011cdf5ab7e.tar.bz2
Added test for failing to unlink cached target files
Diffstat (limited to 'SCons/Taskmaster')
-rw-r--r--SCons/Taskmaster/TaskmasterTests.py59
1 files changed, 56 insertions, 3 deletions
diff --git a/SCons/Taskmaster/TaskmasterTests.py b/SCons/Taskmaster/TaskmasterTests.py
index 9d7f959..95150fd 100644
--- a/SCons/Taskmaster/TaskmasterTests.py
+++ b/SCons/Taskmaster/TaskmasterTests.py
@@ -244,6 +244,12 @@ class Node:
self.executor.targets = self.targets
return self.executor
+ def get_internal_path(self):
+ """
+ Should only be used (currently) by TaskmasterTestCase.test_cached_execute_target_unlink_fails
+ """
+ return str(self)
+
class OtherError(Exception):
pass
@@ -1071,7 +1077,7 @@ class TaskmasterTestCase(unittest.TestCase):
n1 = Node("n1")
# Mark the node as being cached
- n1.cached = 1
+ n1.cached = True
tm = SCons.Taskmaster.Taskmaster([n1])
t = tm.next_task()
t.prepare()
@@ -1081,6 +1087,55 @@ class TaskmasterTestCase(unittest.TestCase):
has_binfo = hasattr(n1, 'binfo')
assert has_binfo, has_binfo
+ def test_cached_execute_target_unlink_fails(self):
+ """Test executing a task with cached targets where unlinking one of the targets fail
+ """
+ global cache_text
+ import SCons.Warnings
+
+ cache_text = []
+ n1 = Node("n1")
+ n2 = Node("not-cached")
+
+ class DummyFS:
+ def unlink(self, _):
+ raise IOError
+
+ n1.fs = DummyFS()
+
+ # Mark the node as being cached
+ n1.cached = True
+ # Add n2 as a target for n1
+ n1.targets.append(n2)
+ # Explicitly mark n2 as not cached
+ n2.cached = False
+
+ # Save SCons.Warnings.warn so we can mock it and catch it being called for unlink failures
+ _save_warn = SCons.Warnings.warn
+ issued_warnings = []
+
+ def fake_warnings_warn(clz, message):
+ nonlocal issued_warnings
+ issued_warnings.append((clz, message))
+ SCons.Warnings.warn = fake_warnings_warn
+
+ tm = SCons.Taskmaster.Taskmaster([n1, n2])
+ t = tm.next_task()
+ t.prepare()
+ t.execute()
+
+ # Restore saved warn
+ SCons.Warnings.warn = _save_warn
+
+ self.assertTrue(len(issued_warnings) == 1,
+ msg='More than expected warnings (1) were issued %d' % len(issued_warnings))
+ self.assertEqual(issued_warnings[0][0], SCons.Warnings.CacheCleanupErrorWarning,
+ msg='Incorrect warning class')
+ self.assertEqual(issued_warnings[0][1],
+ 'Failed copying all target files from cache, Error while attempting to remove file n1 retrieved from cache: ')
+ self.assertEqual(cache_text, ["n1 retrieved"], msg=cache_text)
+
+
def test_exception(self):
"""Test generic Taskmaster exception handling
@@ -1104,8 +1159,6 @@ class TaskmasterTestCase(unittest.TestCase):
t.exception_set(None)
# pass
- # import pdb; pdb.set_trace()
-
# Having this here works for python 2.x,
# but it is a tuple (None, None, None) when called outside
# an except statement