public HostMetricsCollector(HostMetricsSettings settings) { this.settings = settings ?? new HostMetricsSettings(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var collector = new NativeHostMetricsCollector_Windows(this.settings); nativeCollector = collector.Collect; disposeNativeCollector = collector.Dispose; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { var collector = new NativeHostMetricsCollector_Linux(this.settings); nativeCollector = collector.Collect; disposeNativeCollector = collector.Dispose; } cache = new ThrottlingCache <HostMetrics>(CollectInternal, CacheTTL); }
public async Task GetRemovesExpired_Async() { // Arrange ThrottlingCache cache = new ThrottlingCache(); cache.AddAndCleanup("k1", new ThrottlingCacheEntry(_ex1, TimeSpan.FromMilliseconds(1)), _logger); // expired cache.AddAndCleanup("k2", new ThrottlingCacheEntry(_ex2, TimeSpan.FromMilliseconds(10000)), _logger); // Act await Task.Delay(1).ConfigureAwait(false); MsalServiceException foundEx1, foundEx2; bool isFound1 = cache.TryGetOrRemoveExpired("k1", _logger, out foundEx1); bool isFound2 = cache.TryGetOrRemoveExpired("k2", _logger, out foundEx2); // Assert Assert.IsFalse(isFound1, "Should have been removed as it is expired"); Assert.IsTrue(isFound2, "Should have been found as it is not expired"); Assert.IsNull(foundEx1); Assert.AreSame(_ex2, foundEx2); }