public Task MultiplePips_DifferentHash(FakeBuild.CasAccessMethod accessMethod) { // Different hash but same weak fingerprint and CasHash PipDefinition[] pips = { new PipDefinition("PipSameCas", pipSize: 5, hashIndex: 2), new PipDefinition("PipSameCas", pipSize: 5, hashIndex: 3), new PipDefinition("PipSameCas", pipSize: 5, hashIndex: 4) }; const string TestName = nameof(MultiplePips_DifferentHash); return(TestMultiplePipsAsync(TestName, pips, accessMethod)); }
public Task DeterministicTool(FakeBuild.CasAccessMethod accessMethod) { PipDefinition[] pips = { new PipDefinition("PipA", determinism: CacheDeterminism.Tool), new PipDefinition("PipB", determinism: CacheDeterminism.Tool), new PipDefinition("PipC") }; // We will do multiple unique pips and validate that they all ran // These will all have different weak fingerprints const string TestName = nameof(DeterministicTool); return(TestMultiplePipsAsync(TestName, pips, accessMethod)); }
public Task MultiplePips_DifferentWeak(FakeBuild.CasAccessMethod accessMethod) { PipDefinition[] pips = { new PipDefinition("PipA"), new PipDefinition("PipB"), new PipDefinition("PipC") }; // We will do multiple unique pips and validate that they all ran // These will all have different weak fingerprints const string TestName = nameof(MultiplePips_DifferentWeak); return(TestMultiplePipsAsync(TestName, pips, accessMethod)); }
public Task MultiplePips_Mixed(FakeBuild.CasAccessMethod accessMethod) { // Various different pips PipDefinition[] pips = { new PipDefinition("VariousA"), new PipDefinition("VariousSameHash",pipSize: 3), new PipDefinition("VariousSameCas", pipSize: 5, hashIndex: 2), new PipDefinition("VariousB"), new PipDefinition("VariousSameHash",pipSize: 4), new PipDefinition("VariousSameCas", pipSize: 5, hashIndex: 3), new PipDefinition("VariousC"), new PipDefinition("VariousSameHash",pipSize: 5), new PipDefinition("VariousSameCas", pipSize: 5, hashIndex: 4) }; const string TestName = nameof(MultiplePips_Mixed); return(TestMultiplePipsAsync(TestName, pips, accessMethod)); }
/// <summary> /// Helper method to run a set of pip definitions through the cache /// </summary> /// <param name="testName">Name of the test</param> /// <param name="pips">Pip definitions to run</param> /// <param name="accessMethod">Cas access method (stream or file)</param> /// <returns>async task only - no value</returns> protected async Task TestMultiplePipsAsync(string testName, PipDefinition[] pips, FakeBuild.CasAccessMethod accessMethod) { string testCacheId = MakeCacheId(testName + accessMethod); ICache cache = await CreateCacheAsync(testCacheId); // Now for the session (which we base on the cache ID) string testSessionId = "Session1-" + cache.CacheId; ICacheSession session = await CreateSessionAsync(cache, testSessionId); HashSet <FullCacheRecord> records = await pips.BuildAsync(session); XAssert.AreEqual(pips.Length, records.Count, "Should have had {0} cache records generated!", pips.Length); foreach (var record in records) { XAssert.AreEqual(FakeBuild.NewRecordCacheId, record.CacheId); } // Now we see if we can get back the items we think we should await CloseSessionAsync(session, testSessionId); // Check that the content is fine await ValidateSessionAsync(records, cache, testSessionId, accessMethod); // Cache hits test... testSessionId = "Session2-" + cache.CacheId; session = await CreateSessionAsync(cache, testSessionId); foreach (var record in await pips.BuildAsync(session)) { XAssert.AreNotEqual(FakeBuild.NewRecordCacheId, record.CacheId); XAssert.IsTrue(records.Contains(record)); } await CloseSessionAsync(session, testSessionId); // Check that the content is fine await ValidateSessionAsync(records, cache, testSessionId, accessMethod); await ShutdownCacheAsync(cache, testCacheId); }
private async Task ValidateSessionAsync(HashSet <FullCacheRecord> expectedRecords, ICache cache, string sessionId, FakeBuild.CasAccessMethod accessMethod) { if (!ImplementsTrackedSessions || DummySessionName != null) { return; } ICacheReadOnlySession readOnlySession = (await cache.CreateReadOnlySessionAsync()).Success(); // Check that the content is fine HashSet <FullCacheRecord> foundRecords = new HashSet <FullCacheRecord>(); foreach (var strongFingerprintTask in cache.EnumerateSessionStrongFingerprints(DummySessionName ?? sessionId).Success().OutOfOrderTasks()) { StrongFingerprint strongFingerprint = await strongFingerprintTask; CasEntries casEntries = (await readOnlySession.GetCacheEntryAsync(strongFingerprint)).Success(); FullCacheRecord record = new FullCacheRecord(strongFingerprint, casEntries); XAssert.IsTrue(expectedRecords.Contains(record), "Found record that was not expected!"); foundRecords.Add(record); } (await readOnlySession.CloseAsync()).Success(); await FakeBuild.CheckContentsAsync(cache, foundRecords, accessMethod); XAssert.AreEqual(expectedRecords.Count, foundRecords.Count); }