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

[39-74] FlowWireTapSpec #6586

Merged
merged 6 commits into from
Apr 4, 2023
Merged
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
51 changes: 23 additions & 28 deletions src/core/Akka.Streams.Tests/Dsl/FlowWireTapSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Linq;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Streams.Dsl;
using Akka.Streams.TestKit;
Expand All @@ -30,62 +31,56 @@ public FlowWireTapSpec(ITestOutputHelper helper)
}

[Fact]
public void A_wireTap_must_call_the_procedure_for_each_element()
public async Task A_wireTap_must_call_the_procedure_for_each_element()
{
this.AssertAllStagesStopped(() =>
{
Source.From(Enumerable.Range(1, 100))
.WireTap(i => TestActor.Tell(i))
.RunWith(Sink.Ignore<int>(), Materializer).Wait();

Enumerable.Range(1, 100).Select(i => ExpectMsg(i));
await this.AssertAllStagesStoppedAsync(async () => {
Source.From(Enumerable.Range(1, 100))
.WireTap(i => TestActor.Tell(i))
.RunWith(Sink.Ignore<int>(), Materializer).Wait();
foreach (var i in Enumerable.Range(1, 100))
await ExpectMsgAsync(i);
}, Materializer);
}

[Fact]
public void A_wireTap_must_complete_the_future_for_an_empty_stream()
public async Task A_wireTap_must_complete_the_future_for_an_empty_stream()
{
this.AssertAllStagesStopped(() =>
{
Source.Empty<string>()
.WireTap(i => TestActor.Tell(i))
.RunWith(Sink.Ignore<string>(), Materializer)
.ContinueWith(_ => TestActor.Tell("done"));

ExpectMsg("done");

await this.AssertAllStagesStoppedAsync(async() => {
await Source.Empty<string>()
.WireTap(i => TestActor.Tell(i))
.RunWith(Sink.Ignore<string>(), Materializer)
.ContinueWith(_ => TestActor.Tell("done"));
await ExpectMsgAsync("done");
}, Materializer);
}

[Fact]
public void A_wireTap_must_yield_the_first_error()
public async Task A_wireTap_must_yield_the_first_error()
{
this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(async() => {
var p = this.CreateManualPublisherProbe<int>();

Source.FromPublisher(p)
.WireTap(i => TestActor.Tell(i))
.RunWith(Sink.Ignore<int>(), Materializer)
.ContinueWith(t => TestActor.Tell(t.Exception.InnerException));

var proc = p.ExpectSubscription();
proc.ExpectRequest();
var proc = await p.ExpectSubscriptionAsync();
await proc.ExpectRequestAsync();
var rte = new Exception("ex");
proc.SendError(rte);
ExpectMsg(rte);

await ExpectMsgAsync(rte);
}, Materializer);
}

[Fact]
public void A_wireTap_must_no_cause_subsequent_stages_to_be_failed_if_throws()
public async Task A_wireTap_must_no_cause_subsequent_stages_to_be_failed_if_throws()
{
this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(() => {
var error = new TestException("Boom!");
var future = Source.Single(1).WireTap(_ => throw error).RunWith(Sink.Ignore<int>(), Materializer);
Invoking(() => future.Wait()).Should().NotThrow();
return Task.CompletedTask;
}, Materializer);
}
}
Expand Down