Skip to content

Commit

Permalink
Try again
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Aug 21, 2023
1 parent c521bdb commit 4f29dbb
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/MetricsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,34 @@ public sealed class MetricsTests(SubscriptionFixture fixture, ITestOutputHelper

[Fact]
public void Debug() {
_exporter.Collect(Timeout.Infinite);
var values = _exporter.CollectValues();

foreach (var value in values) {
outputHelper.WriteLine(value.ToString());
}
}

[Fact]
public void ShouldMeasureSubscriptionGapDuration() {
var values = _exporter.CollectValues();

var duration = GetValue(values, SubscriptionMetrics.ProcessingRateName)!;

duration.Should().NotBeNull();
GetTag(duration, SubscriptionMetrics.SubscriptionIdTag).Should().Be(SubscriptionId);
GetTag(duration, SubscriptionMetrics.MessageTypeTag).Should().Be(TestEvent.TypeName);
GetTag(duration, "test").Should().Be("foo");
}

[Fact]
public void ShouldMeasureSubscriptionGapCount() {
_exporter.Collect(Timeout.Infinite);
var values = _exporter.CollectValues();

var counter = _host.Services.GetRequiredService<MessageCounter>();
var gapCount = GetValue(values, SubscriptionMetrics.GapCountMetricName)!;
var expected = SubscriptionFixture.Count - counter.Count + 1;
var duration = GetValue(values, SubscriptionMetrics.ProcessingRateName)!;

var expectedGap = SubscriptionFixture.Count - counter.Count + 1;

gapCount.Should().NotBeNull();
gapCount.Value.Should().BeInRange(expected, expected + 5);
gapCount.Value.Should().BeInRange(expectedGap, expectedGap + 5);
GetTag(gapCount, SubscriptionMetrics.SubscriptionIdTag).Should().Be(SubscriptionId);
GetTag(gapCount, "test").Should().Be("foo");

duration.Should().NotBeNull();
GetTag(duration, SubscriptionMetrics.SubscriptionIdTag).Should().Be(SubscriptionId);
GetTag(duration, SubscriptionMetrics.MessageTypeTag).Should().Be(TestEvent.TypeName);
GetTag(duration, "test").Should().Be("foo");
}

static MetricValue? GetValue(MetricValue[] values, string metric)
Expand Down Expand Up @@ -85,8 +82,7 @@ public sealed class MetricsTests(SubscriptionFixture fixture, ITestOutputHelper
await Task.Delay(10);
}

await Task.Delay(200);
_exporter.Collect(Timeout.Infinite);
await Task.Delay(500);
}

public Task DisposeAsync() {
Expand Down

0 comments on commit 4f29dbb

Please sign in to comment.