Skip to content

Commit

Permalink
Merge pull request #100 from thefringeninja/inenumerable
Browse files Browse the repository at this point in the history
Fixed Enumerator Exception Being Overridden w/ DeadlineExceeded
  • Loading branch information
thefringeninja committed Jan 18, 2021
2 parents 0059470 + a82006a commit 73949d1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/EventStore.Client.Streams/EventStoreClient.Append.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ await call.RequestStream.WriteAsync(new AppendReq {
}
}).ConfigureAwait(false);
}

await call.RequestStream.CompleteAsync().ConfigureAwait(false);
} finally {
await call.RequestStream.CompleteAsync().ConfigureAwait(false);

var response = await call.ResponseAsync.ConfigureAwait(false);

if (response.Success != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;

namespace EventStore.Client {
public class append_to_stream_when_events_enumerator_throws
: IClassFixture<append_to_stream_when_events_enumerator_throws.Fixture> {
private readonly Fixture _fixture;

public append_to_stream_when_events_enumerator_throws(Fixture fixture) {
_fixture = fixture;
}

[Fact]
public void throws_the_exception() {
Assert.IsType<EnumerationFailedException>(_fixture.CaughtException);
}

[Fact]
public async Task the_write_does_not_succeed() {
var result = _fixture.Client.ReadStreamAsync(Direction.Forwards, _fixture.StreamName, StreamPosition.Start);
Assert.Equal(ReadState.StreamNotFound, await result.ReadState);
}

private class EnumerationFailedException : Exception {
}

public class Fixture : EventStoreClientFixture {
public string StreamName { get; }

public Fixture() {
StreamName = GetStreamName("stream");
}

public Exception CaughtException { get; private set; }

protected override async Task Given() {
try {
await Client.AppendToStreamAsync(StreamName, StreamRevision.None, Events());
} catch (Exception ex) {
CaughtException = ex;
}

IEnumerable<EventData> Events() {
var i = 0;
foreach (var e in CreateTestEvents(5)) {
if (i++ % 3 == 0) {
throw new EnumerationFailedException();
}

yield return e;
}
}
}

protected override Task When() => Task.CompletedTask;
}
}
}

0 comments on commit 73949d1

Please sign in to comment.