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

[51-74] GraphZipWithSpec #6598

Merged
merged 5 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
59 changes: 28 additions & 31 deletions src/core/Akka.Streams.Tests/Dsl/GraphZipWithSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Akka.Streams.Dsl;
using Akka.Streams.TestKit;
using FluentAssertions;
Expand Down Expand Up @@ -48,23 +49,23 @@ public ZipWithFixture(GraphDsl.Builder<NotUsed> builder) : base(builder)


[Fact]
public void ZipWith_must_work_with_one_immediately_completed_and_one_nonempty_publisher()
public async Task ZipWith_must_work_with_one_immediately_completed_and_one_nonempty_publisher()
{
var subscriber1 = Setup(CompletedPublisher<int>(), NonEmptyPublisher(Enumerable.Range(1, 4)));
subscriber1.ExpectSubscriptionAndComplete();
await subscriber1.ExpectSubscriptionAndCompleteAsync();

var subscriber2 = Setup(NonEmptyPublisher(Enumerable.Range(1, 4)), CompletedPublisher<int>());
subscriber2.ExpectSubscriptionAndComplete();
await subscriber2.ExpectSubscriptionAndCompleteAsync();
}

[Fact]
public void ZipWith_must_work_with_one_delayed_completed_and_one_nonempty_publisher()
public async Task ZipWith_must_work_with_one_delayed_completed_and_one_nonempty_publisher()
{
var subscriber1 = Setup(SoonToCompletePublisher<int>(), NonEmptyPublisher(Enumerable.Range(1, 4)));
subscriber1.ExpectSubscriptionAndComplete();
await subscriber1.ExpectSubscriptionAndCompleteAsync();

var subscriber2 = Setup(NonEmptyPublisher(Enumerable.Range(1, 4)), SoonToCompletePublisher<int>());
subscriber2.ExpectSubscriptionAndComplete();
await subscriber2.ExpectSubscriptionAndCompleteAsync();
}

[Fact]
Expand All @@ -88,17 +89,16 @@ public void ZipWith_must_work_with_one_delayed_failed_and_one_nonempty_publisher
}

[Fact]
public void ZipWith_must_work_in_the_happy_case()
public async Task ZipWith_must_work_in_the_happy_case()
{
this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(async() => {
var probe = this.CreateManualSubscriberProbe<int>();

RunnableGraph.FromGraph(GraphDsl.Create(b =>
{
var zipWith = b.Add(new ZipWith<int, int, int>((i, i1) => i+i1));
var zipWith = b.Add(new ZipWith<int, int, int>((i, i1) => i + i1));
var source1 = Source.From(Enumerable.Range(1, 4));
var source2 = Source.From(new[] {10, 20, 30, 40});
var source2 = Source.From(new[] { 10, 20, 30, 40 });

b.From(source1).To(zipWith.In0);
b.From(source2).To(zipWith.In1);
Expand All @@ -107,27 +107,26 @@ public void ZipWith_must_work_in_the_happy_case()
return ClosedShape.Instance;
})).Run(Materializer);

var subscription = probe.ExpectSubscription();
var subscription = await probe.ExpectSubscriptionAsync();

subscription.Request(2);
probe.ExpectNext( 11, 22);
probe.ExpectNext(11, 22);

subscription.Request(1);
probe.ExpectNext(33);

subscription.Request(1);
probe.ExpectNext(44);

probe.ExpectComplete();
await probe.ExpectCompleteAsync();
}, Materializer);
}


[Fact]
public void ZipWith_must_work_in_the_sad_case()
public async Task ZipWith_must_work_in_the_sad_case()
{
this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(async() => {
var probe = this.CreateManualSubscriberProbe<int>();

RunnableGraph.FromGraph(GraphDsl.Create(b =>
Expand All @@ -143,21 +142,20 @@ public void ZipWith_must_work_in_the_sad_case()
return ClosedShape.Instance;
})).Run(Materializer);

var subscription = probe.ExpectSubscription();
var subscription = await probe.ExpectSubscriptionAsync();

subscription.Request(2);
probe.ExpectNext( 1/-2, 2/-1);
probe.ExpectNext(1 / -2, 2 / -1);
EventFilter.Exception<DivideByZeroException>().ExpectOne(() => subscription.Request(2));
probe.ExpectError().Should().BeOfType<DivideByZeroException>();
probe.ExpectNoMsg(TimeSpan.FromMilliseconds(200));
await probe.ExpectNoMsgAsync(TimeSpan.FromMilliseconds(200));
}, Materializer);
}

[Fact]
public void ZipWith_must_ZipWith_expanded_Person_unapply_3_outputs()
public async Task ZipWith_must_ZipWith_expanded_Person_unapply_3_outputs()
{
this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(async() => {
var probe = this.CreateManualSubscriberProbe<Person>();

RunnableGraph.FromGraph(GraphDsl.Create(b =>
Expand All @@ -175,22 +173,21 @@ public void ZipWith_must_ZipWith_expanded_Person_unapply_3_outputs()
return ClosedShape.Instance;
})).Run(Materializer);

var subscription = probe.ExpectSubscription();
var subscription = await probe.ExpectSubscriptionAsync();

subscription.Request(5);
probe.ExpectNext().Should().BeEquivalentTo(new Person("Caplin", "Capybara", 55));

probe.ExpectComplete();
await probe.ExpectCompleteAsync();
}, Materializer);
}

[Fact]
public void ZipWith_must_work_with_up_to_9_inputs()
public async Task ZipWith_must_work_with_up_to_9_inputs()
{
// the jvm version uses 19 inputs but we have only 9

this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(async() => {
var probe = this.CreateManualSubscriberProbe<string>();

RunnableGraph.FromGraph(GraphDsl.Create(b =>
Expand All @@ -215,11 +212,11 @@ public void ZipWith_must_work_with_up_to_9_inputs()
return ClosedShape.Instance;
})).Run(Materializer);

var subscription = probe.ExpectSubscription();
var subscription = await probe.ExpectSubscriptionAsync();

subscription.Request(1);
probe.ExpectNext(Enumerable.Range(1, 9).Aggregate("", (s, i) => s + i));
probe.ExpectComplete();
await probe.ExpectNextAsync(Enumerable.Range(1, 9).Aggregate("", (s, i) => s + i));
await probe.ExpectCompleteAsync();
}, Materializer);
}

Expand Down