Example #1
0
        public void PruneCache_PruneCacheFolders_WillRemoveOldestFolders()
        {
            PopulateCache(out int filesWritten, out string[] artifactsDirectories);
            BuildCache.ComputeCacheSizeAndFolders(out long currentCacheSize, out List <BuildCache.CacheFolder> cacheFolders);

            // Set folder older
            var folder = cacheFolders[0];

            folder.LastAccessTimeUtc = folder.LastAccessTimeUtc.Subtract(new TimeSpan(1, 0, 0));
            cacheFolders[0]          = folder;

            // delete just under the first folder size
            long maximumCacheSize = currentCacheSize - folder.Length + 1;

            BuildCache.PruneCacheFolders(maximumCacheSize, currentCacheSize, cacheFolders);
            BuildCache.ComputeCacheSizeAndFolders(out long newCurrentCacheSize, out List <BuildCache.CacheFolder> newCacheFolders);

            Assert.AreNotEqual(0, newCurrentCacheSize);
            Assert.GreaterOrEqual(maximumCacheSize, newCurrentCacheSize);
            Assert.AreEqual(artifactsDirectories.Length - 1, newCacheFolders.Count);
        }