Skip to content

Commit ae3809e

Browse files
authored
Convert Akka.Stream.TestKit to async - TestPublisherSubscriberSpec (#5913)
1 parent 36d4ade commit ae3809e

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/core/Akka.Streams.TestKit.Tests/TestPublisherSubscriberSpec.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// </copyright>
66
//-----------------------------------------------------------------------
77

8+
using System.Threading.Tasks;
89
using Akka.Streams.Dsl;
910
using Akka.TestKit;
1011
using FluentAssertions;
@@ -24,55 +25,58 @@ public TestPublisherSubscriberSpec(ITestOutputHelper output = null) : base(outpu
2425
}
2526

2627
[Fact]
27-
public void TestPublisher_and_TestSubscriber_should_have_all_events_accessible_from_manual_probes()
28+
public async Task TestPublisher_and_TestSubscriber_should_have_all_events_accessible_from_manual_probes()
2829
{
29-
this.AssertAllStagesStopped(() =>
30+
await this.AssertAllStagesStoppedAsync( async() =>
3031
{
3132
var upstream = this.CreateManualPublisherProbe<int>();
3233
var downstream = this.CreateManualSubscriberProbe<int>();
3334
Source.FromPublisher(upstream)
3435
.RunWith(Sink.AsPublisher<int>(false), Materializer)
3536
.Subscribe(downstream);
3637

37-
var upstreamSubscription = upstream.ExpectSubscription();
38-
object evt = downstream.ExpectEvent();
38+
var upstreamSubscription = await upstream.ExpectSubscriptionAsync();
39+
object evt = await downstream.ExpectEventAsync();
3940
evt.Should().BeOfType<TestSubscriber.OnSubscribe>();
4041
var downstreamSubscription = ((TestSubscriber.OnSubscribe) evt).Subscription;
4142

4243
upstreamSubscription.SendNext(1);
4344
downstreamSubscription.Request(1);
44-
evt = upstream.ExpectEvent();
45+
evt = await upstream.ExpectEventAsync();
4546
evt.Should().BeOfType<TestPublisher.RequestMore>();
4647
((TestPublisher.RequestMore) evt).NrOfElements.Should().Be(1);
47-
evt = downstream.ExpectEvent();
48+
evt = await downstream.ExpectEventAsync();
4849
evt.Should().BeOfType<TestSubscriber.OnNext<int>>();
4950
((TestSubscriber.OnNext<int>) evt).Element.Should().Be(1);
5051

5152
upstreamSubscription.SendNext(1);
5253
downstreamSubscription.Request(1);
53-
downstream.ExpectNext(1);
54+
await downstream.ExpectNextAsync(1).Task;
5455

5556
upstreamSubscription.SendComplete();
56-
evt = downstream.ExpectEvent();
57+
evt = await downstream.ExpectEventAsync();
5758
evt.Should().BeOfType<TestSubscriber.OnComplete>();
5859
}, Materializer);
5960
}
6061

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

6364
[Fact]
64-
public void TestPublisher_and_TestSubscriber_should_properly_update_PendingRequest_in_ExpectRequest()
65+
public async Task TestPublisher_and_TestSubscriber_should_properly_update_PendingRequest_in_ExpectRequest()
6566
{
66-
var upstream = this.CreatePublisherProbe<int>();
67-
var downstream = this.CreateSubscriberProbe<int>();
67+
await this.AssertAllStagesStoppedAsync(async () =>
68+
{
69+
var upstream = this.CreatePublisherProbe<int>();
70+
var downstream = this.CreateSubscriberProbe<int>();
6871

69-
Source.FromPublisher(upstream).RunWith(Sink.FromSubscriber(downstream), Materializer);
72+
Source.FromPublisher(upstream).RunWith(Sink.FromSubscriber(downstream), Materializer);
7073

71-
downstream.ExpectSubscription().Request(10);
74+
(await downstream.ExpectSubscriptionAsync()).Request(10);
7275

73-
upstream.ExpectRequest().Should().Be(10);
74-
upstream.SendNext(1);
75-
downstream.ExpectNext(1);
76+
(await upstream.ExpectRequestAsync()).Should().Be(10);
77+
upstream.SendNext(1);
78+
await downstream.ExpectNextAsync(1).Task;
79+
}, Materializer);
7680
}
7781
}
7882
}

0 commit comments

Comments
 (0)