@@ -34,183 +34,176 @@ public LazyFlowSpec(ITestOutputHelper helper)
34
34
private static readonly Exception Ex = new TestException ( "" ) ;
35
35
36
36
private static readonly Task < Flow < int , int , NotUsed > > FlowF = Task . FromResult ( Flow . Create < int > ( ) ) ;
37
-
37
+
38
38
[ Fact ]
39
- public void A_LazyFlow_must_work_in_happy_case ( )
39
+ public async Task A_LazyFlow_must_work_in_happy_case ( )
40
40
{
41
- this . AssertAllStagesStopped ( ( ) =>
42
- {
43
- Func < Task < Flow < int , string , NotUsed > > > MapF ( int e ) => ( ) =>
44
- Task . FromResult ( Flow . FromFunction < int , string > ( i => ( i * e ) . ToString ( ) ) ) ;
41
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
42
+ Func < Task < Flow < int , string , NotUsed > > > MapF ( int e ) => ( ) =>
43
+ Task . FromResult ( Flow . FromFunction < int , string > ( i => ( i * e ) . ToString ( ) ) ) ;
45
44
46
45
var probe = Source . From ( Enumerable . Range ( 2 , 10 ) )
47
46
. Via ( Flow . LazyInitAsync ( MapF ( 2 ) ) )
48
47
. RunWith ( this . SinkProbe < string > ( ) , Materializer ) ;
49
48
probe . Request ( 100 ) ;
50
- Enumerable . Range ( 2 , 10 ) . Select ( i => ( i * 2 ) . ToString ( ) ) . ForEach ( i => probe . ExpectNext ( i ) ) ;
49
+ foreach ( var i in Enumerable . Range ( 2 , 10 ) . Select ( i => ( i * 2 ) . ToString ( ) ) )
50
+ {
51
+ await probe . ExpectNextAsync ( i ) ;
52
+ }
51
53
} , Materializer ) ;
52
54
}
53
55
54
56
[ Fact ]
55
- public void A_LazyFlow_must_work_with_slow_flow_init ( )
57
+ public async Task A_LazyFlow_must_work_with_slow_flow_init ( )
56
58
{
57
- this . AssertAllStagesStopped ( ( ) =>
58
- {
59
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
59
60
var p = new TaskCompletionSource < Flow < int , int , NotUsed > > ( ) ;
60
61
var sourceProbe = this . CreateManualPublisherProbe < int > ( ) ;
61
62
var flowProbe = Source . FromPublisher ( sourceProbe )
62
63
. Via ( Flow . LazyInitAsync ( ( ) => p . Task ) )
63
64
. RunWith ( this . SinkProbe < int > ( ) , Materializer ) ;
64
65
65
- var sourceSub = sourceProbe . ExpectSubscription ( ) ;
66
+ var sourceSub = await sourceProbe . ExpectSubscriptionAsync ( ) ;
66
67
flowProbe . Request ( 1 ) ;
67
- sourceSub . ExpectRequest ( 1 ) ;
68
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
68
69
sourceSub . SendNext ( 0 ) ;
69
- sourceSub . ExpectRequest ( 1 ) ;
70
- sourceProbe . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 200 ) ) ;
70
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
71
+ await sourceProbe . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 200 ) ) ;
71
72
72
73
p . SetResult ( Flow . Create < int > ( ) ) ;
73
74
flowProbe . Request ( 99 ) ;
74
- flowProbe . ExpectNext ( 0 ) ;
75
- Enumerable . Range ( 1 , 10 ) . ForEach ( i =>
76
- {
75
+ await flowProbe . ExpectNextAsync ( 0 ) ;
76
+ foreach ( var i in Enumerable . Range ( 0 , 10 ) )
77
+ {
77
78
sourceSub . SendNext ( i ) ;
78
- flowProbe . ExpectNext ( i ) ;
79
- } ) ;
79
+ await flowProbe . ExpectNextAsync ( i ) ;
80
+ }
80
81
sourceSub . SendComplete ( ) ;
81
82
} , Materializer ) ;
82
83
}
83
84
84
85
[ Fact ]
85
- public void A_LazyFlow_must_complete_when_there_was_no_elements_in_stream ( )
86
+ public async Task A_LazyFlow_must_complete_when_there_was_no_elements_in_stream ( )
86
87
{
87
- this . AssertAllStagesStopped ( ( ) =>
88
- {
89
- var probe = Source . Empty < int > ( )
90
- . Via ( Flow . LazyInitAsync ( ( ) => FlowF ) )
91
- . RunWith ( this . SinkProbe < int > ( ) , Materializer ) ;
92
- probe . Request ( 1 ) . ExpectComplete ( ) ;
88
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
89
+ var probe = Source . Empty < int > ( )
90
+ . Via ( Flow . LazyInitAsync ( ( ) => FlowF ) )
91
+ . RunWith ( this . SinkProbe < int > ( ) , Materializer ) ;
92
+ await probe . Request ( 1 ) . ExpectCompleteAsync ( ) ;
93
93
} , Materializer ) ;
94
94
}
95
95
96
96
[ Fact ]
97
- public void A_LazyFlow_must_complete_normally_when_upstream_completes_BEFORE_the_stage_has_switched_to_the_inner_flow ( )
97
+ public async Task A_LazyFlow_must_complete_normally_when_upstream_completes_BEFORE_the_stage_has_switched_to_the_inner_flow ( )
98
98
{
99
- this . AssertAllStagesStopped ( ( ) =>
100
- {
99
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
101
100
var promise = new TaskCompletionSource < Flow < int , int , NotUsed > > ( ) ;
102
101
var ( pub , sub ) = this . SourceProbe < int > ( )
103
102
. ViaMaterialized ( Flow . LazyInitAsync ( ( ) => promise . Task ) , Keep . Left )
104
103
. ToMaterialized ( this . SinkProbe < int > ( ) , Keep . Both )
105
104
. Run ( Materializer ) ;
106
105
107
106
sub . Request ( 1 ) ;
108
- pub . SendNext ( 1 ) . SendComplete ( ) ;
107
+ await pub . SendNext ( 1 ) . SendCompleteAsync ( ) ;
109
108
promise . SetResult ( Flow . Create < int > ( ) ) ;
110
- sub . ExpectNext ( 1 ) . ExpectComplete ( ) ;
109
+ await sub . ExpectNext ( 1 ) . ExpectCompleteAsync ( ) ;
111
110
} , Materializer ) ;
112
111
}
113
112
114
113
[ Fact ]
115
- public void A_LazyFlow_must_complete_normally_when_upstream_completes_AFTER_the_stage_has_switched_to_the_inner_flow ( )
114
+ public async Task A_LazyFlow_must_complete_normally_when_upstream_completes_AFTER_the_stage_has_switched_to_the_inner_flow ( )
116
115
{
117
- this . AssertAllStagesStopped ( ( ) =>
118
- {
119
- var ( pub , sub ) = this . SourceProbe < int > ( )
120
- . ViaMaterialized ( Flow . LazyInitAsync ( ( ) => Task . FromResult ( Flow . Create < int > ( ) ) ) , Keep . Left )
121
- . ToMaterialized ( this . SinkProbe < int > ( ) , Keep . Both )
122
- . Run ( Materializer ) ;
116
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
117
+ var ( pub , sub ) = this . SourceProbe < int > ( )
118
+ . ViaMaterialized ( Flow . LazyInitAsync ( ( ) => Task . FromResult ( Flow . Create < int > ( ) ) ) , Keep . Left )
119
+ . ToMaterialized ( this . SinkProbe < int > ( ) , Keep . Both )
120
+ . Run ( Materializer ) ;
123
121
124
122
sub . Request ( 1 ) ;
125
- pub . SendNext ( 1 ) ;
126
- sub . ExpectNext ( 1 ) ;
127
- pub . SendComplete ( ) ;
128
- sub . ExpectComplete ( ) ;
123
+ await pub . SendNextAsync ( 1 ) ;
124
+ await sub . ExpectNextAsync ( 1 ) ;
125
+ await pub . SendCompleteAsync ( ) ;
126
+ await sub . ExpectCompleteAsync ( ) ;
129
127
} , Materializer ) ;
130
128
}
131
129
132
130
[ Fact ]
133
- public void A_LazyFlow_must_fail_gracefully_when_flow_factory_method_failed ( )
131
+ public async Task A_LazyFlow_must_fail_gracefully_when_flow_factory_method_failed ( )
134
132
{
135
- this . AssertAllStagesStopped ( ( ) =>
136
- {
133
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
137
134
var sourceProbe = this . CreateManualPublisherProbe < int > ( ) ;
138
135
var probe = Source . FromPublisher ( sourceProbe )
139
136
. Via ( Flow . LazyInitAsync < int , int , NotUsed > ( ( ) => throw Ex ) )
140
137
. RunWith ( this . SinkProbe < int > ( ) , Materializer ) ;
141
138
142
- var sourceSub = sourceProbe . ExpectSubscription ( ) ;
139
+ var sourceSub = await sourceProbe . ExpectSubscriptionAsync ( ) ;
143
140
probe . Request ( 1 ) ;
144
- sourceSub . ExpectRequest ( 1 ) ;
141
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
145
142
sourceSub . SendNext ( 0 ) ;
146
- sourceSub . ExpectCancellation ( ) ;
143
+ await sourceSub . ExpectCancellationAsync ( ) ;
147
144
probe . ExpectError ( ) . Should ( ) . Be ( Ex ) ;
148
145
} , Materializer ) ;
149
146
}
150
147
151
148
[ Fact ]
152
- public void A_LazyFlow_must_fail_gracefully_when_upstream_failed ( )
149
+ public async Task A_LazyFlow_must_fail_gracefully_when_upstream_failed ( )
153
150
{
154
- this . AssertAllStagesStopped ( ( ) =>
155
- {
151
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
156
152
var sourceProbe = this . CreateManualPublisherProbe < int > ( ) ;
157
153
var probe = Source . FromPublisher ( sourceProbe )
158
154
. Via ( Flow . LazyInitAsync ( ( ) => FlowF ) )
159
155
. RunWith ( this . SinkProbe < int > ( ) , Materializer ) ;
160
156
161
- var sourceSub = sourceProbe . ExpectSubscription ( ) ;
162
- sourceSub . ExpectRequest ( 1 ) ;
157
+ var sourceSub = await sourceProbe . ExpectSubscriptionAsync ( ) ;
158
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
163
159
sourceSub . SendNext ( 0 ) ;
164
- probe . Request ( 1 ) . ExpectNext ( 0 ) ;
160
+ await probe . Request ( 1 ) . ExpectNextAsync ( 0 ) ;
165
161
sourceSub . SendError ( Ex ) ;
166
162
probe . ExpectError ( ) . Should ( ) . Be ( Ex ) ;
167
163
} , Materializer ) ;
168
164
}
169
165
170
166
[ Fact ]
171
- public void A_LazyFlow_must_fail_gracefully_when_factory_task_failed ( )
167
+ public async Task A_LazyFlow_must_fail_gracefully_when_factory_task_failed ( )
172
168
{
173
- this . AssertAllStagesStopped ( ( ) =>
174
- {
169
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
175
170
var sourceProbe = this . CreateManualPublisherProbe < int > ( ) ;
176
171
var flowprobe = Source . FromPublisher ( sourceProbe )
177
172
. Via ( Flow . LazyInitAsync ( ( ) => Task . FromException < Flow < int , int , NotUsed > > ( Ex ) ) )
178
173
. RunWith ( this . SinkProbe < int > ( ) , Materializer ) ;
179
174
180
- var sourceSub = sourceProbe . ExpectSubscription ( ) ;
181
- sourceSub . ExpectRequest ( 1 ) ;
175
+ var sourceSub = await sourceProbe . ExpectSubscriptionAsync ( ) ;
176
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
182
177
sourceSub . SendNext ( 0 ) ;
183
178
var error = flowprobe . Request ( 1 ) . ExpectError ( ) . As < AggregateException > ( ) ;
184
179
error . Flatten ( ) . InnerException . Should ( ) . Be ( Ex ) ;
185
180
} , Materializer ) ;
186
181
}
187
182
188
183
[ Fact ]
189
- public void A_LazyFlow_must_cancel_upstream_when_the_downstream_is_cancelled ( )
184
+ public async Task A_LazyFlow_must_cancel_upstream_when_the_downstream_is_cancelled ( )
190
185
{
191
- this . AssertAllStagesStopped ( ( ) =>
192
- {
186
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
193
187
var sourceProbe = this . CreateManualPublisherProbe < int > ( ) ;
194
188
var probe = Source . FromPublisher ( sourceProbe )
195
189
. Via ( Flow . LazyInitAsync ( ( ) => FlowF ) )
196
190
. RunWith ( this . SinkProbe < int > ( ) , Materializer ) ;
197
191
198
- var sourceSub = sourceProbe . ExpectSubscription ( ) ;
192
+ var sourceSub = await sourceProbe . ExpectSubscriptionAsync ( ) ;
199
193
probe . Request ( 1 ) ;
200
- sourceSub . ExpectRequest ( 1 ) ;
194
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
201
195
sourceSub . SendNext ( 0 ) ;
202
- sourceSub . ExpectRequest ( 1 ) ;
203
- probe . ExpectNext ( 0 ) ;
196
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
197
+ await probe . ExpectNextAsync ( 0 ) ;
204
198
probe . Cancel ( ) ;
205
- sourceSub . ExpectCancellation ( ) ;
199
+ await sourceSub . ExpectCancellationAsync ( ) ;
206
200
} , Materializer ) ;
207
201
}
208
202
209
203
[ Fact ]
210
- public void A_LazyFlow_must_fail_correctly_when_factory_throw_error ( )
204
+ public async Task A_LazyFlow_must_fail_correctly_when_factory_throw_error ( )
211
205
{
212
- this . AssertAllStagesStopped ( ( ) =>
213
- {
206
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
214
207
const string msg = "fail!" ;
215
208
var matFail = new TestException ( msg ) ;
216
209
@@ -220,6 +213,7 @@ public void A_LazyFlow_must_fail_correctly_when_factory_throw_error()
220
213
. Invoking ( source => source . Run ( Materializer ) ) ;
221
214
222
215
result . Should ( ) . Throw < TestException > ( ) . WithMessage ( msg ) ;
216
+ return Task . CompletedTask ;
223
217
} , Materializer ) ;
224
218
}
225
219
}
0 commit comments