Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
w1am committed Oct 21, 2024
1 parent 33adcb8 commit 5e5fa68
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ReSharper disable ConditionalAccessQualifierIsNonNullableAccordingToAPIContract

using EventStore.Client.Diagnostics;
using EventStore.Diagnostics.Tracing;

Expand Down Expand Up @@ -172,54 +174,48 @@ async Task Subscribe(IAsyncEnumerator<StreamMessage> internalEnumerator) {
}
}

[Fact]
[Trait("Category", "Special cases")]
public async Task should_not_trace_when_event_is_null() {
var category = Guid.NewGuid().ToString("N");
var streamName = category + "-123";

var seedEvents = Fixture.CreateTestEvents(type: $"{category}-{Fixture.GetStreamName()}").ToArray();
await Fixture.Streams.AppendToStreamAsync(streamName, StreamState.NoStream, seedEvents);
await Fixture.Streams.DeleteAsync(streamName, StreamState.StreamExists);
[Fact]
[Trait("Category", "Special cases")]
public async Task should_not_trace_when_event_is_null() {
var category = Guid.NewGuid().ToString("N");
var streamName = category + "-123";

await using var subscription = Fixture.Streams.SubscribeToStream("$ce-" + category, FromStream.Start, resolveLinkTos: true);
var seedEvents = Fixture.CreateTestEvents(type: $"{category}-{Fixture.GetStreamName()}").ToArray();
await Fixture.Streams.AppendToStreamAsync(streamName, StreamState.NoStream, seedEvents);

var ex = await Assert.ThrowsAsync<NullReferenceException>(
async () => {
await using var enumerator = subscription.Messages.GetAsyncEnumerator();
await Fixture.Streams.DeleteAsync(streamName, StreamState.StreamExists);

Assert.True(await enumerator.MoveNextAsync());
await using var subscription = Fixture.Streams.SubscribeToStream("$ce-" + category, FromStream.Start, resolveLinkTos: true);

Assert.IsType<StreamMessage.SubscriptionConfirmation>(enumerator.Current);
await using var enumerator = subscription.Messages.GetAsyncEnumerator();

await Subscribe().WithTimeout();
Assert.True(await enumerator.MoveNextAsync());

var appendActivities = Fixture
.GetActivitiesForOperation(TracingConstants.Operations.Append, "$ce-" + category)
.ShouldNotBeNull();
Assert.IsType<StreamMessage.SubscriptionConfirmation>(enumerator.Current);

var subscribeActivities = Fixture
.GetActivitiesForOperation(TracingConstants.Operations.Subscribe, "$ce-" + category)
.ToArray();
await Subscribe().WithTimeout();

appendActivities.ShouldHaveSingleItem();
subscribeActivities.ShouldBeEmpty();
var appendActivities = Fixture
.GetActivitiesForOperation(TracingConstants.Operations.Append, streamName)
.ShouldNotBeNull();

return;
var subscribeActivities = Fixture
.GetActivitiesForOperation(TracingConstants.Operations.Subscribe, "$ce-" + category)
.ToArray();

async Task Subscribe() {
while (await enumerator.MoveNextAsync()) {
if (enumerator.Current is not StreamMessage.Event(var resolvedEvent))
continue;
appendActivities.ShouldHaveSingleItem();
subscribeActivities.ShouldBeEmpty();

resolvedEvent.Event.Data.ShouldNotBe(null);
return;

return;
}
}
}
).WithTimeout();
async Task Subscribe() {
while (await enumerator.MoveNextAsync()) {
if (enumerator.Current is not StreamMessage.Event(var resolvedEvent))
continue;

Assert.NotNull(ex);
}
if (resolvedEvent.Event?.EventType is "$metadata")
return;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ async Task Subscribe() {

[Fact]
[Trait("Category", "Special cases")]
[Description("This is normal behavior for EventStoreDB")]
public async Task should_throw_exception_when_subscribing_to_deleted_stream_category() {
var category = Guid.NewGuid().ToString("N");
var streamName = category + "-123";
Expand All @@ -257,18 +258,15 @@ public async Task should_throw_exception_when_subscribing_to_deleted_stream_cate

async Task Subscribe() {
while (await enumerator.MoveNextAsync()) {
if (enumerator.Current is not StreamMessage.Event(var resolvedEvent)) {
if (enumerator.Current is not StreamMessage.Event(var resolvedEvent))
continue;
}

resolvedEvent.Event.Data.ShouldNotBe(null);

return;
_ = resolvedEvent.Event.Data;
}
}
}
).WithTimeout();

Assert.NotNull(ex);
ex.ShouldNotBeNull();
}
}

0 comments on commit 5e5fa68

Please sign in to comment.