def _do_test_successful_request_cleans_result_dir(self, cache, key): with self.setup_test_file(cache.artifact_root) as path: with temporary_dir() as results_dir: with temporary_file_path(root_dir=results_dir) as canary: call_insert((cache, key, [path], False)) call_use_cached_files((cache, key, results_dir)) # Results content should have been deleted. self.assertFalse(os.path.exists(canary))
def test_failed_multiproc(self): key = CacheKey('muppet_key', 'fake_hash') # Failed requests should return failure status, but not raise exceptions with self.setup_rest_cache(return_failed=True) as cache: self.assertFalse(call_use_cached_files((cache, key, None))) with self.setup_test_file(cache.artifact_root) as path: call_insert((cache, key, [path], False)) self.assertFalse(call_use_cached_files((cache, key, None)))
def test_multiproc(self): key = CacheKey('muppet_key', 'fake_hash') with self.setup_local_cache() as cache: self.assertFalse(call_use_cached_files((cache, key, None))) with self.setup_test_file(cache.artifact_root) as path: call_insert((cache, key, [path], False)) self.assertTrue(call_use_cached_files((cache, key, None))) with self.setup_rest_cache() as cache: self.assertFalse(call_use_cached_files((cache, key, None))) with self.setup_test_file(cache.artifact_root) as path: call_insert((cache, key, [path], False)) self.assertTrue(call_use_cached_files((cache, key, None)))
def test_noops_after_max_retries_exceeded(self): key = CacheKey("muppet_key", "fake_hash") with self.setup_rest_cache() as cache: # Assert that the artifact doesn't exist, then insert it and check that it exists. self.assertFalse(call_use_cached_files((cache, key, None))) with self.setup_test_file(cache.artifact_root) as path: call_insert((cache, key, [path], False)) self.assertTrue(call_use_cached_files((cache, key, None))) # No failed requests should have occurred yet, so no retries should have been triggered. self.assertFalse(RequestsSession._max_retries_exceeded) # Now assert that when max retries are exceeded, the cache returns 404s. with self.restore_max_retries_flag(): RequestsSession._max_retries_exceeded = True self.assertFalse(call_use_cached_files((cache, key, None))) # After the flag is toggled back, the cache successfully finds the entry. self.assertTrue(call_use_cached_files((cache, key, None)))