From 6a9bb1f1d2b7832e927dd9714db1a187b1c9f461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Si=C3=B1uela?= Date: Wed, 26 Oct 2016 14:36:07 +0200 Subject: [PATCH 1/2] Add tests checking behaviour after objects and manifests are evicted --- integrationtests.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/integrationtests.py b/integrationtests.py index 7d06ff2a..0cbe38ed 100644 --- a/integrationtests.py +++ b/integrationtests.py @@ -1106,6 +1106,36 @@ def testBasedir(self): self.assertEqual(stats.numCacheHits(), 1) +class TestCleanCache(unittest.TestCase): + def testEvictedObject(self): + with cd(os.path.join(ASSETS_DIR, "hits-and-misses")), tempfile.TemporaryDirectory() as tempDir: + customEnv = dict(os.environ, CLCACHE_DIR=tempDir) + cmd = CLCACHE_CMD + ["/nologo", "/EHsc", "/c", 'hit.cpp'] + + # Compile once to insert the object in the cache + subprocess.check_call(cmd, env=customEnv) + + # Remove object + cache = clcache.Cache(tempDir) + cache.compilerArtifactsRepository.clean(0) + + self.assertEqual(subprocess.call(cmd, env=customEnv), 0) + + def testEvictedManifest(self): + with cd(os.path.join(ASSETS_DIR, "hits-and-misses")), tempfile.TemporaryDirectory() as tempDir: + customEnv = dict(os.environ, CLCACHE_DIR=tempDir) + cmd = CLCACHE_CMD + ["/nologo", "/EHsc", "/c", 'hit.cpp'] + + # Compile once to insert the object in the cache + subprocess.check_call(cmd, env=customEnv) + + # Remove manifest + cache = clcache.Cache(tempDir) + cache.manifestRepository.clean(0) + + self.assertEqual(subprocess.call(cmd, env=customEnv), 0) + + if __name__ == '__main__': unittest.TestCase.longMessage = True unittest.main() From a396f2b3439759806f2af05821728fd0918cc681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Si=C3=B1uela?= Date: Wed, 26 Oct 2016 15:55:24 +0200 Subject: [PATCH 2/2] postprocessUnusableManifestMiss: check if the object is already in the cache before trying to write it --- clcache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clcache.py b/clcache.py index 4bf37c27..e9d77f42 100644 --- a/clcache.py +++ b/clcache.py @@ -1432,7 +1432,7 @@ def postprocessUnusableManifestMiss( section = cache.compilerArtifactsRepository.section(cachekey) with section.lock, cache.statistics.lock, cache.statistics as stats: reason(stats) - if returnCode == 0 and os.path.exists(objectFile): + if returnCode == 0 and os.path.exists(objectFile) and not section.hasEntry(cachekey): artifacts = CompilerArtifacts(objectFile, compilerOutput, compilerStderr) cleanupRequired = addObjectToCache(stats, cache, section, cachekey, artifacts) manifest = createOrUpdateManifest(manifestSection, manifestHash, entry)