Skip to content

Commit 2f402be

Browse files
authored
[55-74] LazySourceSpec (#6602)
* [55-74] `LazySourceSpec` * Changes to `async/await`
1 parent 707c370 commit 2f402be

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

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

+38-41
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using FluentAssertions;
2020
using Xunit;
2121
using FluentAssertions.Extensions;
22+
using Xunit.Sdk;
2223

2324
namespace Akka.Streams.Tests.Dsl
2425
{
@@ -30,11 +31,11 @@ public LazySourceSpec()
3031
}
3132

3233
private ActorMaterializer Materializer { get; }
33-
34+
3435
[Fact]
35-
public void A_lazy_source_must_work_like_a_normal_source_happy_path()
36+
public async Task A_lazy_source_must_work_like_a_normal_source_happy_path()
3637
{
37-
this.AssertAllStagesStopped(async() =>
38+
await this.AssertAllStagesStoppedAsync(async() =>
3839
{
3940
var result = Source.Lazily(() => Source.From(new[] { 1, 2, 3 })).RunWith(Sink.Seq<int>(), Materializer);
4041
var complete = await result.ShouldCompleteWithin(3.Seconds());
@@ -43,10 +44,9 @@ public void A_lazy_source_must_work_like_a_normal_source_happy_path()
4344
}
4445

4546
[Fact]
46-
public void A_lazy_source_must_work_never_construct_the_source_when_there_was_no_demand()
47+
public async Task A_lazy_source_must_work_never_construct_the_source_when_there_was_no_demand()
4748
{
48-
this.AssertAllStagesStopped(() =>
49-
{
49+
await this.AssertAllStagesStoppedAsync(() => {
5050
var probe = this.CreateSubscriberProbe<int>();
5151
var constructed = new AtomicBoolean();
5252
Source.Lazily(() =>
@@ -57,49 +57,48 @@ public void A_lazy_source_must_work_never_construct_the_source_when_there_was_no
5757

5858
probe.Cancel();
5959
constructed.Value.Should().BeFalse();
60+
return Task.CompletedTask;
6061
}, Materializer);
6162
}
6263

6364
[Fact]
64-
public void A_lazy_source_must_fail_the_materialized_value_when_downstream_cancels_without_ever_consuming_any_element()
65+
public async Task A_lazy_source_must_fail_the_materialized_value_when_downstream_cancels_without_ever_consuming_any_element()
6566
{
66-
this.AssertAllStagesStopped(() =>
67-
{
68-
var result = Source.Lazily(() => Source.From(new[] { 1, 2, 3 }))
69-
.ToMaterialized(Sink.Cancelled<int>(), Keep.Left)
70-
.Run(Materializer);
67+
await this.AssertAllStagesStoppedAsync(() => {
68+
var result = Source.Lazily(() => Source.From(new[] { 1, 2, 3 }))
69+
.ToMaterialized(Sink.Cancelled<int>(), Keep.Left)
70+
.Run(Materializer);
7171

72-
Intercept(() =>
72+
AssertThrows<Exception>(() =>
7373
{
7474
var boom = result.Result;
7575
});
76+
return Task.CompletedTask;
7677
}, Materializer);
7778
}
7879

7980
[Fact]
80-
public void A_lazy_source_must_stop_consuming_when_downstream_has_cancelled()
81+
public async Task A_lazy_source_must_stop_consuming_when_downstream_has_cancelled()
8182
{
82-
this.AssertAllStagesStopped(() =>
83-
{
83+
await this.AssertAllStagesStoppedAsync(async() => {
8484
var outProbe = this.CreateSubscriberProbe<int>();
8585
var inProbe = this.CreatePublisherProbe<int>();
8686

8787
Source.Lazily(() => Source.FromPublisher(inProbe)).RunWith(Sink.FromSubscriber(outProbe), Materializer);
8888

8989
outProbe.Request(1);
90-
inProbe.ExpectRequest();
91-
inProbe.SendNext(27);
92-
outProbe.ExpectNext(27);
93-
outProbe.Cancel();
94-
inProbe.ExpectCancellation();
90+
await inProbe.ExpectRequestAsync();
91+
await inProbe.SendNextAsync(27);
92+
await outProbe.ExpectNextAsync(27);
93+
await outProbe.CancelAsync();
94+
await inProbe.ExpectCancellationAsync();
9595
}, Materializer);
9696
}
9797

9898
[Fact]
99-
public void A_lazy_source_must_materialize_when_the_source_has_been_created()
99+
public async Task A_lazy_source_must_materialize_when_the_source_has_been_created()
100100
{
101-
this.AssertAllStagesStopped(() =>
102-
{
101+
await this.AssertAllStagesStoppedAsync(async() => {
103102
var probe = this.CreateSubscriberProbe<int>();
104103

105104
var task = Source.Lazily(() => Source.From(new[] { 1, 2, 3 }).MapMaterializedValue(_ => Done.Instance))
@@ -108,18 +107,17 @@ public void A_lazy_source_must_materialize_when_the_source_has_been_created()
108107

109108
task.IsCompleted.Should().BeFalse();
110109
probe.Request(1);
111-
probe.ExpectNext(1);
110+
await probe.ExpectNextAsync(1);
112111
task.Result.Should().Be(Done.Instance);
113112

114113
probe.Cancel();
115114
}, Materializer);
116115
}
117116

118117
[Fact]
119-
public void A_lazy_source_must_propagate_downstream_cancellation_cause_when_inner_source_has_been_materialized()
118+
public async Task A_lazy_source_must_propagate_downstream_cancellation_cause_when_inner_source_has_been_materialized()
120119
{
121-
this.AssertAllStagesStopped(() =>
122-
{
120+
await this.AssertAllStagesStoppedAsync(async() => {
123121
var probe = CreateTestProbe();
124122
var (doneF, killSwitch) = Source.Lazily(() =>
125123
{
@@ -138,7 +136,7 @@ public void A_lazy_source_must_propagate_downstream_cancellation_cause_when_inne
138136
.Run(Materializer);
139137

140138
var boom = new TestException("boom");
141-
probe.ExpectMsg<Done>();
139+
await probe.ExpectMsgAsync<Done>();
142140
killSwitch.Abort(boom);
143141
doneF.ContinueWith(t =>
144142
{
@@ -150,19 +148,18 @@ public void A_lazy_source_must_propagate_downstream_cancellation_cause_when_inne
150148
}
151149

152150
[Fact]
153-
public void A_lazy_source_must_fail_stage_when_upstream_fails()
151+
public async Task A_lazy_source_must_fail_stage_when_upstream_fails()
154152
{
155-
this.AssertAllStagesStopped(() =>
156-
{
153+
await this.AssertAllStagesStoppedAsync(async() => {
157154
var outProbe = this.CreateSubscriberProbe<int>();
158155
var inProbe = this.CreatePublisherProbe<int>();
159156

160157
Source.Lazily(() => Source.FromPublisher(inProbe)).RunWith(Sink.FromSubscriber(outProbe), Materializer);
161158

162159
outProbe.Request(1);
163-
inProbe.ExpectRequest();
164-
inProbe.SendNext(27);
165-
outProbe.ExpectNext(27);
160+
await inProbe.ExpectRequestAsync();
161+
await inProbe.SendNextAsync(27);
162+
await outProbe.ExpectNextAsync(27);
166163

167164
var testException = new TestException("OMG Who set that on fire !?!");
168165
inProbe.SendError(testException);
@@ -171,9 +168,9 @@ public void A_lazy_source_must_fail_stage_when_upstream_fails()
171168
}
172169

173170
[Fact]
174-
public void A_lazy_source_must_propagate_attributes_to_inner_stream()
171+
public async Task A_lazy_source_must_propagate_attributes_to_inner_stream()
175172
{
176-
this.AssertAllStagesStopped(async() =>
173+
await this.AssertAllStagesStoppedAsync(async() =>
177174
{
178175
var attributesSource = Source.FromGraph(new AttibutesSourceStage())
179176
.AddAttributes(Attributes.CreateName("inner"));
@@ -193,9 +190,9 @@ public void A_lazy_source_must_propagate_attributes_to_inner_stream()
193190
}
194191

195192
[Fact]
196-
public void A_lazy_source_must_fail_correctly_when_materialization_of_inner_source_fails()
193+
public async Task A_lazy_source_must_fail_correctly_when_materialization_of_inner_source_fails()
197194
{
198-
this.AssertAllStagesStopped(() =>
195+
await this.AssertAllStagesStoppedAsync(() =>
199196
{
200197
var matFail = new TestException("fail!");
201198

@@ -207,12 +204,12 @@ public void A_lazy_source_must_fail_correctly_when_materialization_of_inner_sour
207204
{
208205
task.Wait(TimeSpan.FromSeconds(1));
209206
}
210-
catch (AggregateException) {}
207+
catch (AggregateException) { }
211208

212209
task.IsFaulted.ShouldBe(true);
213210
task.Exception.ShouldNotBe(null);
214211
task.Exception.InnerException.Should().BeEquivalentTo(matFail);
215-
212+
return Task.CompletedTask;
216213
}, Materializer);
217214
}
218215

0 commit comments

Comments
 (0)