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

Convert Akka.Stream.TestKit to async - TestPublisherSubscriberSpec #5913

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
36 changes: 20 additions & 16 deletions src/core/Akka.Streams.TestKit.Tests/TestPublisherSubscriberSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------

using System.Threading.Tasks;
using Akka.Streams.Dsl;
using Akka.TestKit;
using FluentAssertions;
Expand All @@ -24,55 +25,58 @@ public TestPublisherSubscriberSpec(ITestOutputHelper output = null) : base(outpu
}

[Fact]
public void TestPublisher_and_TestSubscriber_should_have_all_events_accessible_from_manual_probes()
public async Task TestPublisher_and_TestSubscriber_should_have_all_events_accessible_from_manual_probes()
{
this.AssertAllStagesStopped(() =>
await this.AssertAllStagesStoppedAsync( async() =>
{
var upstream = this.CreateManualPublisherProbe<int>();
var downstream = this.CreateManualSubscriberProbe<int>();
Source.FromPublisher(upstream)
.RunWith(Sink.AsPublisher<int>(false), Materializer)
.Subscribe(downstream);

var upstreamSubscription = upstream.ExpectSubscription();
object evt = downstream.ExpectEvent();
var upstreamSubscription = await upstream.ExpectSubscriptionAsync();
object evt = await downstream.ExpectEventAsync();
evt.Should().BeOfType<TestSubscriber.OnSubscribe>();
var downstreamSubscription = ((TestSubscriber.OnSubscribe) evt).Subscription;

upstreamSubscription.SendNext(1);
downstreamSubscription.Request(1);
evt = upstream.ExpectEvent();
evt = await upstream.ExpectEventAsync();
evt.Should().BeOfType<TestPublisher.RequestMore>();
((TestPublisher.RequestMore) evt).NrOfElements.Should().Be(1);
evt = downstream.ExpectEvent();
evt = await downstream.ExpectEventAsync();
evt.Should().BeOfType<TestSubscriber.OnNext<int>>();
((TestSubscriber.OnNext<int>) evt).Element.Should().Be(1);

upstreamSubscription.SendNext(1);
downstreamSubscription.Request(1);
downstream.ExpectNext(1);
await downstream.ExpectNextAsync(1).Task;

upstreamSubscription.SendComplete();
evt = downstream.ExpectEvent();
evt = await downstream.ExpectEventAsync();
evt.Should().BeOfType<TestSubscriber.OnComplete>();
}, Materializer);
}

// "handle gracefully partial function that is not suitable" does not apply

[Fact]
public void TestPublisher_and_TestSubscriber_should_properly_update_PendingRequest_in_ExpectRequest()
public async Task TestPublisher_and_TestSubscriber_should_properly_update_PendingRequest_in_ExpectRequest()
{
var upstream = this.CreatePublisherProbe<int>();
var downstream = this.CreateSubscriberProbe<int>();
await this.AssertAllStagesStoppedAsync(async () =>
{
var upstream = this.CreatePublisherProbe<int>();
var downstream = this.CreateSubscriberProbe<int>();

Source.FromPublisher(upstream).RunWith(Sink.FromSubscriber(downstream), Materializer);
Source.FromPublisher(upstream).RunWith(Sink.FromSubscriber(downstream), Materializer);

downstream.ExpectSubscription().Request(10);
(await downstream.ExpectSubscriptionAsync()).Request(10);

upstream.ExpectRequest().Should().Be(10);
upstream.SendNext(1);
downstream.ExpectNext(1);
(await upstream.ExpectRequestAsync()).Should().Be(10);
upstream.SendNext(1);
await downstream.ExpectNextAsync(1).Task;
}, Materializer);
}
}
}