public void ExceptionInDetach_Throws() { var source = new FailureMetricSource(throwOnDetach: true); var collector = new MetricsCollector( new MetricsCollectorOptions { Endpoints = new[] { new MetricEndpoint("Local", new LocalMetricHandler()), }, Sources = new[] { source }, RetryInterval = TimeSpan.Zero, SnapshotInterval = TimeSpan.FromMilliseconds(20), } ); collector.Start(); Assert.Throws <Exception>(() => collector.Stop()); }
public async Task MetricSourcesAreAttachedAndDetached() { var metricSource = new TestMetricSource(); var collector = new MetricsCollector( new MetricsCollectorOptions { Endpoints = new [] { new MetricEndpoint("Local", new LocalMetricHandler()), }, Sources = new[] { metricSource }, RetryInterval = TimeSpan.Zero, SnapshotInterval = TimeSpan.FromMilliseconds(20), } ); collector.Start(); try { // make sure initialization happened await Task.WhenAny(metricSource.AttachTask, Task.Delay(1000)); Assert.True(metricSource.AttachTask.IsCompleted, "Metric source was not attached"); // make sure we got snapshotted await Task.WhenAny(metricSource.SnapshotTask, Task.Delay(30000)); Assert.True(metricSource.SnapshotTask.IsCompleted, "Metric source was not snapshotted"); } finally { collector.Stop(); // make sure we got detached await Task.WhenAny(metricSource.DetachTask, Task.Delay(1000)); Assert.True(metricSource.DetachTask.IsCompleted, "Metric source was not detached"); } }