Skip to content

Commit 1ebbb4d

Browse files
eabaAaronontheweb
andauthored
[37-74] FlowWatchTerminationSpec (#6584)
* [37-74] `FlowWatchTerminationSpec` * Change to `async` TestKit --------- Co-authored-by: Aaron Stannard <[email protected]>
1 parent 2042810 commit 1ebbb4d

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

src/core/Akka.Streams.Tests/Dsl/FlowWatchTerminationSpec.cs

+34-34
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System;
99
using System.Linq;
1010
using System.Threading;
11+
using System.Threading.Tasks;
1112
using Akka.Streams.Dsl;
1213
using Akka.Streams.TestKit;
1314
using Akka.TestKit;
@@ -28,83 +29,81 @@ public FlowWatchTerminationSpec(ITestOutputHelper helper) : base(helper)
2829
}
2930

3031
[Fact]
31-
public void A_WatchTermination_must_complete_the_future_when_stream_is_completed()
32+
public async Task A_WatchTermination_must_complete_the_future_when_stream_is_completed()
3233
{
33-
this.AssertAllStagesStopped(() =>
34-
{
35-
var t =
36-
Source.From(Enumerable.Range(1, 4))
37-
.WatchTermination(Keep.Right)
38-
.ToMaterialized(this.SinkProbe<int>(), Keep.Both)
39-
.Run(Materializer);
34+
await this.AssertAllStagesStoppedAsync(async() => {
35+
var t =
36+
Source.From(Enumerable.Range(1, 4))
37+
.WatchTermination(Keep.Right)
38+
.ToMaterialized(this.SinkProbe<int>(), Keep.Both)
39+
.Run(Materializer);
4040
var future = t.Item1;
4141
var p = t.Item2;
4242

43-
p.Request(4).ExpectNext( 1, 2, 3, 4);
43+
p.Request(4).ExpectNext(1, 2, 3, 4);
4444
future.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue();
45-
p.ExpectComplete();
45+
await p.ExpectCompleteAsync();
4646
}, Materializer);
4747
}
4848

4949
[Fact]
50-
public void A_WatchTermination_must_complete_the_future_when_stream_is_cancelled_from_downstream()
50+
public async Task A_WatchTermination_must_complete_the_future_when_stream_is_cancelled_from_downstream()
5151
{
52-
this.AssertAllStagesStopped(() =>
53-
{
54-
var t =
55-
Source.From(Enumerable.Range(1, 4))
56-
.WatchTermination(Keep.Right)
57-
.ToMaterialized(this.SinkProbe<int>(), Keep.Both)
58-
.Run(Materializer);
52+
await this.AssertAllStagesStoppedAsync(() => {
53+
var t =
54+
Source.From(Enumerable.Range(1, 4))
55+
.WatchTermination(Keep.Right)
56+
.ToMaterialized(this.SinkProbe<int>(), Keep.Both)
57+
.Run(Materializer);
5958
var future = t.Item1;
6059
var p = t.Item2;
6160

62-
p.Request(3).ExpectNext( 1, 2, 3);
61+
p.Request(3).ExpectNext(1, 2, 3);
6362
p.Cancel();
6463
future.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue();
64+
return Task.CompletedTask;
6565
}, Materializer);
6666
}
6767

6868
[Fact]
69-
public void A_WatchTermination_must_fail_the_future_when_stream_is_failed()
69+
public async Task A_WatchTermination_must_fail_the_future_when_stream_is_failed()
7070
{
71-
this.AssertAllStagesStopped(() =>
72-
{
71+
await this.AssertAllStagesStoppedAsync(() => {
7372
var ex = new Exception("Stream failed.");
7473
var t = this.SourceProbe<int>().WatchTermination(Keep.Both).To(Sink.Ignore<int>()).Run(Materializer);
7574
var p = t.Item1;
7675
var future = t.Item2;
7776
p.SendNext(1);
7877
p.SendError(ex);
7978
future.Invoking(f => f.Wait()).Should().Throw<Exception>().WithMessage("Stream failed.");
79+
return Task.CompletedTask;
8080
}, Materializer);
8181
}
8282

8383
[Fact]
84-
public void A_WatchTermination_must_complete_the_future_for_an_empty_stream()
84+
public async Task A_WatchTermination_must_complete_the_future_for_an_empty_stream()
8585
{
86-
this.AssertAllStagesStopped(() =>
87-
{
88-
var t =
89-
Source.Empty<int>()
90-
.WatchTermination(Keep.Right)
91-
.ToMaterialized(this.SinkProbe<int>(), Keep.Both)
92-
.Run(Materializer);
86+
await this.AssertAllStagesStoppedAsync(() => {
87+
var t =
88+
Source.Empty<int>()
89+
.WatchTermination(Keep.Right)
90+
.ToMaterialized(this.SinkProbe<int>(), Keep.Both)
91+
.Run(Materializer);
9392
var future = t.Item1;
9493
var p = t.Item2;
9594
p.Request(1);
9695
future.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue();
96+
return Task.CompletedTask;
9797
}, Materializer);
9898
}
9999

100100
[Fact(Skip = "We need a way to combine multiple sources with different materializer types")]
101-
public void A_WatchTermination_must_complete_the_future_for_graph()
101+
public async Task A_WatchTermination_must_complete_the_future_for_graph()
102102
{
103-
this.AssertAllStagesStopped(() =>
104-
{
103+
await this.AssertAllStagesStoppedAsync(() => {
105104
//var first = this.SourceProbe<int>().WatchTermination(Keep.Both);
106105
//var second = Source.From(Enumerable.Range(2, 4)).MapMaterializedValue(new Func<NotUsed, (TestPublisher.Probe<int>, Task)>(_ => null));
107-
106+
108107
//var t = Source.FromGraph(
109108
// GraphDsl.Create<SourceShape<int>, (TestPublisher.Probe<int>, Task)>(b =>
110109
// {
@@ -128,6 +127,7 @@ public void A_WatchTermination_must_complete_the_future_for_graph()
128127

129128
//sourceProbe.SendComplete();
130129
//sinkProbe.ExpectNextN(new[] {2, 3, 4, 5}).ExpectComplete();
130+
return Task.CompletedTask;
131131
}, Materializer);
132132
}
133133

0 commit comments

Comments
 (0)