-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix context check in trace subscription method
- Loading branch information
Showing
6 changed files
with
129 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...EventStore.Client.Streams.Tests/Subscriptions/SubscriptionsTracingInstrumentationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using EventStore.Diagnostics.Tracing; | ||
|
||
namespace EventStore.Client.PersistentSubscriptions.Tests.SubscriptionToStream; | ||
|
||
[Trait("Category", "Diagnostics:Tracing")] | ||
public class SubscriptionsTracingInstrumentationTests( | ||
ITestOutputHelper output, | ||
DiagnosticsFixture fixture | ||
) | ||
: EventStoreTests<DiagnosticsFixture>(output, fixture) { | ||
[Fact] | ||
public async Task json_metadata_event_is_traced_and_non_json_metadata_event_is_not_traced() { | ||
var streamName = Fixture.GetStreamName(); | ||
|
||
var seedEvents = new[] { | ||
Fixture.CreateTestEvent(metadata: Fixture.CreateTestJsonMetadata()), | ||
Fixture.CreateTestEvent(metadata: Fixture.CreateTestNonJsonMetadata()) | ||
}; | ||
|
||
var availableEvents = new HashSet<Uuid>(seedEvents.Select(x => x.EventId)); | ||
|
||
await Fixture.Streams.AppendToStreamAsync(streamName, StreamState.NoStream, seedEvents); | ||
|
||
await using var subscription = Fixture.Streams.SubscribeToStream(streamName, FromStream.Start); | ||
await using var enumerator = subscription.Messages.GetAsyncEnumerator(); | ||
|
||
var appendActivities = Fixture | ||
.GetActivitiesForOperation(TracingConstants.Operations.Append, streamName) | ||
.ShouldNotBeNull(); | ||
|
||
Assert.True(await enumerator.MoveNextAsync()); | ||
|
||
Assert.IsType<StreamMessage.SubscriptionConfirmation>(enumerator.Current); | ||
|
||
await Subscribe(availableEvents, enumerator).WithTimeout(); | ||
|
||
var subscribeActivities = Fixture | ||
.GetActivitiesForOperation(TracingConstants.Operations.Subscribe, streamName) | ||
.ToArray(); | ||
|
||
appendActivities.ShouldHaveSingleItem(); | ||
|
||
subscribeActivities.ShouldHaveSingleItem(); | ||
|
||
subscribeActivities.First().ParentId.ShouldBe(appendActivities.First().Id); | ||
|
||
var jsonMetadataEvent = seedEvents.First(); | ||
|
||
Fixture.AssertSubscriptionActivityHasExpectedTags( | ||
subscribeActivities.First(), | ||
streamName, | ||
jsonMetadataEvent.EventId.ToString() | ||
); | ||
} | ||
|
||
static async Task Subscribe(HashSet<Uuid> availableEvents, IAsyncEnumerator<StreamMessage> enumerator) { | ||
while (await enumerator.MoveNextAsync()) { | ||
if (enumerator.Current is not StreamMessage.Event(var resolvedEvent)) | ||
continue; | ||
|
||
availableEvents.Remove(resolvedEvent.Event.EventId); | ||
|
||
if (availableEvents.Count == 0) | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters