public async Task TestGcReadFailure() { string cacheConfig = TestType.NewCache(nameof(TestGcReadFailure), true); BasicFilesystemCache cache = (await InitializeCacheAsync(cacheConfig).SuccessAsync()) as BasicFilesystemCache; XAssert.IsNotNull(cache, "Failed to create cache for GC tests!"); PipDefinition[] pips = { new PipDefinition("Pip1", pipSize: 3), new PipDefinition("Pip2", pipSize: 4) }; bool disconnectErrorReported = false; // Assumes that the cache will be erroring out because of a file access error and not because of some // other random reason. cache.SuscribeForCacheStateDegredationFailures((failure) => { disconnectErrorReported = true; }); CacheEntries files = await BuildPipsAndGetCacheEntries(cache, "Build", pips); // We will hold on to one of the files in the fingerprints in such a way as to fail the GC FileInfo fileInfo = files.FingerprintFiles.Values.Last(); using (var fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.None)) { var failureExpected = cache.CollectUnreferencedCasItems(m_output); XAssert.IsFalse(failureExpected.Succeeded, "Failed to stop CAS GC even when a fingerprint was not readable!"); } // This time, we need to hold onto a session file - preventing the reading of roots var sessionFiles = new DirectoryInfo(cache.SessionRoot).GetFiles(); using (var fileStream = sessionFiles[0].Open(FileMode.Open, FileAccess.Read, FileShare.None)) { var failureExpected = cache.CollectUnreferencedFingerprints(m_output); XAssert.IsFalse(failureExpected.Succeeded, "Failed to stop Fingerprint GC even when a session was not readable!"); } // After these errors, the cache should have disconnected due to lack of access to the session file XAssert.IsTrue(cache.IsDisconnected); XAssert.IsTrue(disconnectErrorReported); AssertSuccess(await cache.ShutdownAsync()); }