Skip to content

Commit 6556856

Browse files
committed
Improve test
1 parent 41bff08 commit 6556856

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Aspire.Dashboard/Otlp/Model/OtlpTrace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void AddSpan(OtlpSpan span)
7070
if (HasCircularReference(span))
7171
{
7272
Spans.Remove(span);
73-
throw new InvalidOperationException($"Circular loop detected for span '{span.SpanId}'.");
73+
throw new InvalidOperationException($"Circular loop detected for span '{span.SpanId}' with parent '{span.ParentSpanId}'.");
7474
}
7575

7676
if (string.IsNullOrEmpty(span.ParentSpanId))

tests/Aspire.Dashboard.Tests/TelemetryRepositoryTests/TraceTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using Aspire.Dashboard.Otlp.Storage;
99
using Google.Protobuf;
1010
using Google.Protobuf.Collections;
11+
using Microsoft.Extensions.Logging;
12+
using Microsoft.Extensions.Logging.Testing;
1113
using OpenTelemetry.Proto.Common.V1;
1214
using OpenTelemetry.Proto.Trace.V1;
1315
using Xunit;
@@ -94,7 +96,10 @@ public void AddTraces()
9496
public void AddTraces_SelfParent_Reject()
9597
{
9698
// Arrange
97-
var repository = CreateRepository();
99+
var testSink = new TestSink();
100+
var factory = LoggerFactory.Create(b => b.AddProvider(new TestLoggerProvider(testSink)));
101+
102+
var repository = CreateRepository(loggerFactory: factory);
98103

99104
// Act
100105
var addContext = new AddContext();
@@ -137,6 +142,10 @@ public void AddTraces_SelfParent_Reject()
137142
Filters = []
138143
});
139144
Assert.Empty(traces.PagedResult.Items);
145+
146+
var write = Assert.Single(testSink.Writes);
147+
Assert.Equal("Error adding span.", write.Message);
148+
Assert.Equal("Circular loop detected for span '312d31' with parent '312d31'.", write.Exception!.Message);
140149
}
141150

142151
[Fact]

0 commit comments

Comments
 (0)