Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stream deletion tests when there are existing events [DB-573] #276

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions test/EventStore.Client.Streams.Tests/subscribe_to_stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Task EventAppeared(StreamSubscription s, ResolvedEvent e, CancellationToken ct)
}

[Fact]
public async Task catches_deletions() {
public async Task catches_deletions_when_stream_has_no_existing_events() {
var stream = _fixture.GetStreamName();

var dropped = new TaskCompletionSource<(SubscriptionDroppedReason, Exception?)>();
Expand All @@ -253,6 +253,36 @@ public async Task catches_deletions() {
void SubscriptionDropped(StreamSubscription s, SubscriptionDroppedReason reason, Exception? ex) => dropped.SetResult((reason, ex));
}

[Fact]
public async Task catches_deletions_when_stream_has_existing_events() {
var stream = _fixture.GetStreamName();

var dropped = new TaskCompletionSource<(SubscriptionDroppedReason, Exception?)>();

await _fixture.Client.AppendToStreamAsync(stream, StreamState.NoStream, _fixture.CreateTestEvents());

using var _ = await _fixture.Client
.SubscribeToStreamAsync(
stream,
FromStream.Start,
EventAppeared,
false,
SubscriptionDropped
)
.WithTimeout();

await _fixture.Client.TombstoneAsync(stream, StreamState.StreamExists);
var (reason, ex) = await dropped.Task.WithTimeout();

Assert.Equal(SubscriptionDroppedReason.ServerError, reason);
var sdex = Assert.IsType<StreamDeletedException>(ex);
Assert.Equal(stream, sdex.Stream);

Task EventAppeared(StreamSubscription s, ResolvedEvent e, CancellationToken ct) => Task.CompletedTask;

void SubscriptionDropped(StreamSubscription s, SubscriptionDroppedReason reason, Exception? ex) => dropped.SetResult((reason, ex));
}

public class Fixture : EventStoreClientFixture {
public Fixture() => Events = CreateTestEvents(10).ToArray();

Expand All @@ -262,4 +292,4 @@ public class Fixture : EventStoreClientFixture {

protected override Task When() => Task.CompletedTask;
}
}
}
34 changes: 32 additions & 2 deletions test/EventStore.Client.Streams.Tests/subscribe_to_stream_live.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
}

[Fact]
public async Task catches_deletions() {
public async Task catches_deletions_when_stream_has_no_existing_events() {
var stream = _fixture.GetStreamName();

var dropped = new TaskCompletionSource<(SubscriptionDroppedReason, Exception?)>();
Expand All @@ -147,7 +147,7 @@
.WithTimeout();

await _fixture.Client.TombstoneAsync(stream, StreamState.NoStream);
var (reason, ex) = await dropped.Task.WithTimeout();

Check failure on line 150 in test/EventStore.Client.Streams.Tests/subscribe_to_stream_live.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Streams/ubuntu-latest/net6.0/ci

EventStore.Client.Streams.Tests.subscribe_to_stream_live.catches_deletions_when_stream_has_no_existing_events

System.TimeoutException : Timed out waiting for task

Check failure on line 150 in test/EventStore.Client.Streams.Tests/subscribe_to_stream_live.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Streams/ubuntu-latest/net7.0/ci

EventStore.Client.Streams.Tests.subscribe_to_stream_live.catches_deletions_when_stream_has_no_existing_events

System.TimeoutException : Timed out waiting for task

Check failure on line 150 in test/EventStore.Client.Streams.Tests/subscribe_to_stream_live.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Streams/ubuntu-latest/net5.0/ci

EventStore.Client.Streams.Tests.subscribe_to_stream_live.catches_deletions_when_stream_has_no_existing_events

System.TimeoutException : Timed out waiting for task

Assert.Equal(SubscriptionDroppedReason.ServerError, reason);
var sdex = Assert.IsType<StreamDeletedException>(ex);
Expand All @@ -158,8 +158,38 @@
void SubscriptionDropped(StreamSubscription s, SubscriptionDroppedReason reason, Exception? ex) => dropped.SetResult((reason, ex));
}

[Fact]
public async Task catches_deletions_when_stream_has_existing_events() {
var stream = _fixture.GetStreamName();

var dropped = new TaskCompletionSource<(SubscriptionDroppedReason, Exception?)>();

await _fixture.Client.AppendToStreamAsync(stream, StreamState.NoStream, _fixture.CreateTestEvents());

using var _ = await _fixture.Client
.SubscribeToStreamAsync(
stream,
FromStream.End,
EventAppeared,
false,
SubscriptionDropped
)
.WithTimeout();

await _fixture.Client.TombstoneAsync(stream, StreamState.StreamExists);
var (reason, ex) = await dropped.Task.WithTimeout();

Check failure on line 180 in test/EventStore.Client.Streams.Tests/subscribe_to_stream_live.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Streams/ubuntu-latest/net6.0/ci

EventStore.Client.Streams.Tests.subscribe_to_stream_live.catches_deletions_when_stream_has_existing_events

System.TimeoutException : Timed out waiting for task

Check failure on line 180 in test/EventStore.Client.Streams.Tests/subscribe_to_stream_live.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Streams/ubuntu-latest/net7.0/ci

EventStore.Client.Streams.Tests.subscribe_to_stream_live.catches_deletions_when_stream_has_existing_events

System.TimeoutException : Timed out waiting for task

Check failure on line 180 in test/EventStore.Client.Streams.Tests/subscribe_to_stream_live.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Streams/ubuntu-latest/net5.0/ci

EventStore.Client.Streams.Tests.subscribe_to_stream_live.catches_deletions_when_stream_has_existing_events

System.TimeoutException : Timed out waiting for task

Assert.Equal(SubscriptionDroppedReason.ServerError, reason);
var sdex = Assert.IsType<StreamDeletedException>(ex);
Assert.Equal(stream, sdex.Stream);

Task EventAppeared(StreamSubscription s, ResolvedEvent e, CancellationToken ct) => Task.CompletedTask;

void SubscriptionDropped(StreamSubscription s, SubscriptionDroppedReason reason, Exception? ex) => dropped.SetResult((reason, ex));
}

public class Fixture : EventStoreClientFixture {
protected override Task Given() => Task.CompletedTask;
protected override Task When() => Task.CompletedTask;
}
}
}
Loading