public void RecordsAnErrorIfStartedTwice() { TimespanMetricType metric = new TimespanMetricType( category: "telemetry", disabled: false, lifetime: Lifetime.Application, name: "timespan_metric", sendInPings: new string[] { "store1", "store2" }, timeUnit: TimeUnit.Millisecond ); // Record a timespan. metric.Start(); metric.Start(); metric.Stop(); // Check that data was properly recorded in the second ping. Assert.True(metric.TestHasValue("store2")); Assert.True(metric.TestGetValue("store2") >= 0); Assert.Equal(1, metric.TestGetNumRecordedErrors(ErrorType.InvalidState)); }
public void APISavesToSecondaryPings() { TimespanMetricType metric = new TimespanMetricType( category: "telemetry", disabled: false, lifetime: Lifetime.Application, name: "timespan_metric", sendInPings: new string[] { "store1", "store2" }, timeUnit: TimeUnit.Millisecond ); metric.Start(); metric.Stop(); // Check that data was properly recorded in the second ping. Assert.True(metric.TestHasValue("store2")); Assert.True(metric.TestGetValue("store2") >= 0); }
public void APIMustCorrectlyCancel() { TimespanMetricType metric = new TimespanMetricType( category: "telemetry", disabled: false, lifetime: Lifetime.Application, name: "timespan_metric", sendInPings: new string[] { "store1" }, timeUnit: TimeUnit.Millisecond ); // Record a timespan. metric.Start(); metric.Cancel(); metric.Stop(); // Check that data was not recorded. Assert.False(metric.TestHasValue(), "The API should not record an error if the metric is cancelled"); Assert.Equal(1, metric.TestGetNumRecordedErrors(ErrorType.InvalidState)); }
public void SetRawNanosDoesNotOverwriteValue() { ulong timespanNanos = 6 * 1000000000L; TimespanMetricType metric = new TimespanMetricType( category: "telemetry", disabled: false, lifetime: Lifetime.Ping, name: "explicit_timespan_1", sendInPings: new string[] { "store1" }, timeUnit: TimeUnit.Second ); metric.Start(); metric.Stop(); ulong value = metric.TestGetValue(); metric.SetRawNanos(timespanNanos); Assert.Equal <ulong>(value, metric.TestGetValue()); }
public void DisabledTimespansMustNotRecordData() { TimespanMetricType metric = new TimespanMetricType( category: "telemetry", disabled: true, lifetime: Lifetime.Application, name: "timespan_metric", sendInPings: new string[] { "store1" }, timeUnit: TimeUnit.Millisecond ); // Record a timespan. metric.Start(); metric.Stop(); // Let's also call cancel() to make sure it's a no-op. metric.Cancel(); // Check that data was not recorded. Assert.False(metric.TestHasValue(), "The API should not record a counter if metric is disabled"); }
public void SetRawNanosDoesNothingWhenTimerIsRunning() { ulong timespanNanos = 1000000000L; TimespanMetricType metric = new TimespanMetricType( category: "telemetry", disabled: false, lifetime: Lifetime.Ping, name: "explicit_timespan", sendInPings: new string[] { "store1" }, timeUnit: TimeUnit.Second ); metric.Start(); metric.SetRawNanos(timespanNanos); metric.Stop(); // If setRawNanos worked, (which it's not supposed to in this case), it would // have recorded 1000000000 ns == 1s. Make sure it's not that. Assert.NotEqual <ulong>(1, metric.TestGetValue()); }
public void ValueUnchangedIfStoppedTwice() { TimespanMetricType metric = new TimespanMetricType( category: "telemetry", disabled: false, lifetime: Lifetime.Application, name: "timespan_metric", sendInPings: new string[] { "store1" }, timeUnit: TimeUnit.Millisecond ); // Record a timespan. metric.Start(); metric.Stop(); Assert.True(metric.TestHasValue()); ulong value = metric.TestGetValue(); metric.Stop(); Assert.Equal(value, metric.TestGetValue()); }
public void TestSetRawNanosFollowedByOtherAPI() { ulong timespanNanos = 6 * 1000000000L; TimespanMetricType metric = new TimespanMetricType( category: "telemetry", disabled: false, lifetime: Lifetime.Ping, name: "explicit_timespan", sendInPings: new string[] { "store1" }, timeUnit: TimeUnit.Second ); metric.SetRawNanos(timespanNanos); Assert.Equal <ulong>(6, metric.TestGetValue()); metric.Start(); metric.Stop(); ulong value = metric.TestGetValue(); Assert.Equal <ulong>(6, value); }