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

[43-74] GraphConcatSpec #6590

Merged
merged 4 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
72 changes: 33 additions & 39 deletions src/core/Akka.Streams.Tests/Dsl/GraphConcatSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ public ConcatFixture(GraphDsl.Builder<NotUsed> builder) : base(builder)
}

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

RunnableGraph.FromGraph(GraphDsl.Create(b =>
Expand All @@ -65,71 +64,68 @@ public void Concat_must_work_in_the_happy_case()
return ClosedShape.Instance;
})).Run(Materializer);

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

for (var i = 1; i <= 10; i++)
{
subscription.Request(1);
probe.ExpectNext(i);
await probe.ExpectNextAsync(i);
}

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

[Fact]
public void Concat_must_work_with_one_immediately_completed_and_one_nonempty_publisher()
public async Task Concat_must_work_with_one_immediately_completed_and_one_nonempty_publisher()
{
this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(async() => {
var subscriber1 = Setup(CompletedPublisher<int>(), NonEmptyPublisher(Enumerable.Range(1, 4)));
var subscription1 = subscriber1.ExpectSubscription();
var subscription1 = await subscriber1.ExpectSubscriptionAsync();

subscription1.Request(5);
subscriber1.ExpectNext( 1, 2, 3, 4).ExpectComplete();
await subscriber1.ExpectNext(1, 2, 3, 4).ExpectCompleteAsync();

var subscriber2 = Setup(NonEmptyPublisher(Enumerable.Range(1, 4)), CompletedPublisher<int>());
var subscription2 = subscriber2.ExpectSubscription();
var subscription2 = await subscriber2.ExpectSubscriptionAsync();

subscription2.Request(5);
subscriber2.ExpectNext( 1, 2, 3, 4).ExpectComplete();
await subscriber2.ExpectNext(1, 2, 3, 4).ExpectCompleteAsync();
}, Materializer);
}

[Fact]
public void Concat_must_work_with_one_delayed_completed_and_one_nonempty_publisher()
public async Task Concat_must_work_with_one_delayed_completed_and_one_nonempty_publisher()
{
this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(async() => {
var subscriber1 = Setup(SoonToCompletePublisher<int>(), NonEmptyPublisher(Enumerable.Range(1, 4)));
var subscription1 = subscriber1.ExpectSubscription();
var subscription1 = await subscriber1.ExpectSubscriptionAsync();

subscription1.Request(5);
subscriber1.ExpectNext( 1, 2, 3, 4).ExpectComplete();
await subscriber1.ExpectNext(1, 2, 3, 4).ExpectCompleteAsync();

var subscriber2 = Setup(NonEmptyPublisher(Enumerable.Range(1, 4)), SoonToCompletePublisher<int>());
var subscription2 = subscriber2.ExpectSubscription();
var subscription2 = await subscriber2.ExpectSubscriptionAsync();

subscription2.Request(5);
subscriber2.ExpectNext( 1, 2, 3, 4).ExpectComplete();
await subscriber2.ExpectNext(1, 2, 3, 4).ExpectCompleteAsync();
}, Materializer);
}

[Fact]
public void Concat_must_work_with_one_immediately_failed_and_one_nonempty_publisher()
public async Task Concat_must_work_with_one_immediately_failed_and_one_nonempty_publisher()
{
this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(async() => {
var subscriber1 = Setup(FailedPublisher<int>(), NonEmptyPublisher(Enumerable.Range(1, 4)));
subscriber1.ExpectSubscriptionAndError().Should().Be(TestException());

var subscriber2 = Setup(NonEmptyPublisher(Enumerable.Range(1, 4)), FailedPublisher<int>());
subscriber2.ExpectSubscription().Request(5);
foreach (var i in Enumerable.Range(1,4))
(await subscriber2.ExpectSubscriptionAsync()).Request(5);

foreach (var i in Enumerable.Range(1, 4))
{
var result = subscriber2.ExpectNextOrError();
if(result is int && (int)result == i)
if (result is int && (int)result == i)
continue;
if (result.Equals(TestException()))
return;
Expand All @@ -140,12 +136,11 @@ public void Concat_must_work_with_one_immediately_failed_and_one_nonempty_publis
}

[Fact]
public void Concat_must_work_with_one_nonempty_publisher_and_one_delayed_failed_and()
public async Task Concat_must_work_with_one_nonempty_publisher_and_one_delayed_failed_and()
{
this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(async() => {
var subscriber = Setup(NonEmptyPublisher(Enumerable.Range(1, 4)), SoonToFailPublisher<int>());
subscriber.ExpectSubscription().Request(5);
(await subscriber.ExpectSubscriptionAsync()).Request(5);

foreach (var i in Enumerable.Range(1, 4))
{
Expand All @@ -161,20 +156,19 @@ public void Concat_must_work_with_one_nonempty_publisher_and_one_delayed_failed_
}

[Fact]
public void Concat_must_work_with_one_delayed_failed_and_one_nonempty_publisher()
public async Task Concat_must_work_with_one_delayed_failed_and_one_nonempty_publisher()
{
this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(() => {
var subscriber1 = Setup(SoonToFailPublisher<int>(), NonEmptyPublisher(Enumerable.Range(1, 4)));
subscriber1.ExpectSubscriptionAndError().Should().Be(TestException());
return Task.CompletedTask;
}, Materializer);
}

[Fact]
public void Concat_must_correctly_handle_async_errors_in_secondary_upstream()
public async Task Concat_must_correctly_handle_async_errors_in_secondary_upstream()
{
this.AssertAllStagesStopped(() =>
{
await this.AssertAllStagesStoppedAsync(async() => {
var promise = new TaskCompletionSource<int>();
var subscriber = this.CreateManualSubscriberProbe<int>();

Expand All @@ -191,9 +185,9 @@ public void Concat_must_correctly_handle_async_errors_in_secondary_upstream()
})).Run(Materializer);


var subscription = subscriber.ExpectSubscription();
var subscription = await subscriber.ExpectSubscriptionAsync();
subscription.Request(4);
subscriber.ExpectNext( 1, 2, 3);
subscriber.ExpectNext(1, 2, 3);
promise.SetException(TestException());
subscriber.ExpectError().Should().Be(TestException());
}, Materializer);
Expand Down