9
9
using System . Collections ;
10
10
using System . Collections . Generic ;
11
11
using System . Linq ;
12
+ using System . Threading . Tasks ;
12
13
using Akka . Pattern ;
13
14
using Akka . Streams . Dsl ;
14
15
using Akka . Streams . TestKit ;
@@ -40,7 +41,7 @@ protected override Source<int, NotUsed> CreateSource(int elements)
40
41
=> Source . From ( Enumerable . Range ( 1 , elements ) ) ;
41
42
42
43
[ Fact ]
43
- public void A_Flow_based_on_an_iterable_must_produce_OnError_when_iterator_throws ( )
44
+ public async Task A_Flow_based_on_an_iterable_must_produce_OnError_when_iterator_throws ( )
44
45
{
45
46
var iterable = Enumerable . Range ( 1 , 3 ) . Select ( x =>
46
47
{
@@ -51,37 +52,37 @@ public void A_Flow_based_on_an_iterable_must_produce_OnError_when_iterator_throw
51
52
var p = Source . From ( iterable ) . RunWith ( Sink . AsPublisher < int > ( false ) , Materializer ) ;
52
53
var c = this . CreateManualSubscriberProbe < int > ( ) ;
53
54
p . Subscribe ( c ) ;
54
- var sub = c . ExpectSubscription ( ) ;
55
+ var sub = await c . ExpectSubscriptionAsync ( ) ;
55
56
sub . Request ( 1 ) ;
56
- c . ExpectNext ( 1 ) ;
57
- c . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 100 ) ) ;
57
+ await c . ExpectNextAsync ( 1 ) ;
58
+ await c . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 100 ) ) ;
58
59
EventFilter . Exception < AggregateException > ( )
59
60
. And . Exception < IllegalStateException > ( "not two" ) . ExpectOne ( ( ) => sub . Request ( 2 ) ) ;
60
61
var error = c . ExpectError ( ) . InnerException ;
61
62
error . Message . Should ( ) . Be ( "not two" ) ;
62
63
sub . Request ( 2 ) ;
63
- c . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 100 ) ) ;
64
+ await c . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 100 ) ) ;
64
65
}
65
66
66
67
[ Fact ]
67
- public void A_Flow_based_on_an_iterable_must_produce_OnError_when_Source_construction_throws ( )
68
+ public async Task A_Flow_based_on_an_iterable_must_produce_OnError_when_Source_construction_throws ( )
68
69
{
69
70
var p = Source . From ( new ThrowEnumerable ( ) ) . RunWith ( Sink . AsPublisher < int > ( false ) , Materializer ) ;
70
71
var c = this . CreateManualSubscriberProbe < int > ( ) ;
71
72
p . Subscribe ( c ) ;
72
73
c . ExpectSubscriptionAndError ( ) . Message . Should ( ) . Be ( "no good iterator" ) ;
73
- c . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 100 ) ) ;
74
+ await c . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 100 ) ) ;
74
75
}
75
76
76
77
[ Fact ]
77
- public void A_Flow_based_on_an_iterable_must_produce_OnError_when_MoveNext_throws ( )
78
+ public async Task A_Flow_based_on_an_iterable_must_produce_OnError_when_MoveNext_throws ( )
78
79
{
79
80
var p = Source . From ( new ThrowEnumerable ( false ) ) . RunWith ( Sink . AsPublisher < int > ( false ) , Materializer ) ;
80
81
var c = this . CreateManualSubscriberProbe < int > ( ) ;
81
82
p . Subscribe ( c ) ;
82
83
var error = c . ExpectSubscriptionAndError ( ) . InnerException ;
83
84
error . Message . Should ( ) . Be ( "no next" ) ;
84
- c . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 100 ) ) ;
85
+ await c . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 100 ) ) ;
85
86
}
86
87
87
88
private sealed class ThrowEnumerable : IEnumerable < int >
@@ -145,158 +146,151 @@ protected AbstractFlowIteratorSpec(ITestOutputHelper helper) : base(helper)
145
146
protected abstract Source < int , NotUsed > CreateSource ( int elements ) ;
146
147
147
148
[ Fact ]
148
- public void A_Flow_based_on_an_iterable_must_produce_elements ( )
149
+ public async Task A_Flow_based_on_an_iterable_must_produce_elements ( )
149
150
{
150
- this . AssertAllStagesStopped ( ( ) =>
151
- {
151
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
152
152
var p = CreateSource ( 3 ) . RunWith ( Sink . AsPublisher < int > ( false ) , Materializer ) ;
153
153
var c = this . CreateManualSubscriberProbe < int > ( ) ;
154
-
154
+
155
155
p . Subscribe ( c ) ;
156
- var sub = c . ExpectSubscription ( ) ;
156
+ var sub = await c . ExpectSubscriptionAsync ( ) ;
157
157
158
158
sub . Request ( 1 ) ;
159
- c . ExpectNext ( 1 ) ;
160
- c . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 100 ) ) ;
159
+ await c . ExpectNextAsync ( 1 ) ;
160
+ await c . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 100 ) ) ;
161
161
sub . Request ( 3 ) ;
162
- c . ExpectNext ( 2 )
162
+ await c . ExpectNext ( 2 )
163
163
. ExpectNext ( 3 )
164
- . ExpectComplete ( ) ;
164
+ . ExpectCompleteAsync ( ) ;
165
165
} , Materializer ) ;
166
166
}
167
167
168
168
[ Fact ]
169
- public void A_Flow_based_on_an_iterable_must_complete_empty ( )
169
+ public async Task A_Flow_based_on_an_iterable_must_complete_empty ( )
170
170
{
171
- this . AssertAllStagesStopped ( ( ) =>
172
- {
171
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
173
172
var p = CreateSource ( 0 ) . RunWith ( Sink . AsPublisher < int > ( false ) , Materializer ) ;
174
173
var c = this . CreateManualSubscriberProbe < int > ( ) ;
175
174
176
175
p . Subscribe ( c ) ;
177
- c . ExpectSubscriptionAndComplete ( ) ;
178
- c . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 100 ) ) ;
176
+ await c . ExpectSubscriptionAndCompleteAsync ( ) ;
177
+ await c . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 100 ) ) ;
179
178
} , Materializer ) ;
180
179
}
181
180
182
181
[ Fact ]
183
- public void A_Flow_based_on_an_iterable_must_produce_elements_with_multiple_subscribers ( )
182
+ public async Task A_Flow_based_on_an_iterable_must_produce_elements_with_multiple_subscribers ( )
184
183
{
185
- this . AssertAllStagesStopped ( ( ) =>
186
- {
184
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
187
185
var p = CreateSource ( 3 ) . RunWith ( Sink . AsPublisher < int > ( true ) , Materializer ) ;
188
186
var c1 = this . CreateManualSubscriberProbe < int > ( ) ;
189
187
var c2 = this . CreateManualSubscriberProbe < int > ( ) ;
190
-
188
+
191
189
p . Subscribe ( c1 ) ;
192
190
p . Subscribe ( c2 ) ;
193
- var sub1 = c1 . ExpectSubscription ( ) ;
194
- var sub2 = c2 . ExpectSubscription ( ) ;
191
+ var sub1 = await c1 . ExpectSubscriptionAsync ( ) ;
192
+ var sub2 = await c2 . ExpectSubscriptionAsync ( ) ;
195
193
sub1 . Request ( 1 ) ;
196
194
sub2 . Request ( 2 ) ;
197
- c1 . ExpectNext ( 1 ) ;
198
- c2 . ExpectNext ( 1 ) ;
199
- c2 . ExpectNext ( 2 ) ;
200
- c1 . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 100 ) ) ;
201
- c2 . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 100 ) ) ;
195
+ await c1 . ExpectNextAsync ( 1 ) ;
196
+ await c2 . ExpectNextAsync ( 1 ) ;
197
+ await c2 . ExpectNextAsync ( 2 ) ;
198
+ await c1 . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 100 ) ) ;
199
+ await c2 . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 100 ) ) ;
202
200
sub1 . Request ( 2 ) ;
203
201
sub2 . Request ( 2 ) ;
204
- c1 . ExpectNext ( 2 ) ;
205
- c1 . ExpectNext ( 3 ) ;
206
- c2 . ExpectNext ( 3 ) ;
207
- c1 . ExpectComplete ( ) ;
208
- c2 . ExpectComplete ( ) ;
202
+ await c1 . ExpectNextAsync ( 2 ) ;
203
+ await c1 . ExpectNextAsync ( 3 ) ;
204
+ await c2 . ExpectNextAsync ( 3 ) ;
205
+ await c1 . ExpectCompleteAsync ( ) ;
206
+ await c2 . ExpectCompleteAsync ( ) ;
209
207
} , Materializer ) ;
210
208
}
211
209
212
210
[ Fact ]
213
- public void A_Flow_based_on_an_iterable_must_produce_elements_to_later_subscriber ( )
211
+ public async Task A_Flow_based_on_an_iterable_must_produce_elements_to_later_subscriber ( )
214
212
{
215
- this . AssertAllStagesStopped ( ( ) =>
216
- {
213
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
217
214
var p = CreateSource ( 3 ) . RunWith ( Sink . AsPublisher < int > ( true ) , Materializer ) ;
218
215
var c1 = this . CreateManualSubscriberProbe < int > ( ) ;
219
216
var c2 = this . CreateManualSubscriberProbe < int > ( ) ;
220
-
217
+
221
218
p . Subscribe ( c1 ) ;
222
- var sub1 = c1 . ExpectSubscription ( ) ;
219
+ var sub1 = await c1 . ExpectSubscriptionAsync ( ) ;
223
220
sub1 . Request ( 1 ) ;
224
- c1 . ExpectNext ( 1 , TimeSpan . FromSeconds ( 60 ) ) ;
225
- c1 . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 100 ) ) ;
221
+ await c1 . ExpectNextAsync ( 1 , TimeSpan . FromSeconds ( 60 ) ) ;
222
+ await c1 . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 100 ) ) ;
226
223
227
224
p . Subscribe ( c2 ) ;
228
- var sub2 = c2 . ExpectSubscription ( ) ;
225
+ var sub2 = await c2 . ExpectSubscriptionAsync ( ) ;
229
226
sub2 . Request ( 3 ) ;
230
227
//element 1 is already gone
231
- c2 . ExpectNext ( 2 )
228
+ await c2 . ExpectNext ( 2 )
232
229
. ExpectNext ( 3 )
233
- . ExpectComplete ( ) ;
230
+ . ExpectCompleteAsync ( ) ;
234
231
235
232
sub1 . Request ( 3 ) ;
236
- c1 . ExpectNext ( 2 )
233
+ await c1 . ExpectNext ( 2 )
237
234
. ExpectNext ( 3 )
238
- . ExpectComplete ( ) ;
235
+ . ExpectCompleteAsync ( ) ;
239
236
} , Materializer ) ;
240
237
}
241
238
242
239
[ Fact ]
243
- public void A_Flow_based_on_an_iterable_must_produce_elements_with_one_transformation_step ( )
240
+ public async Task A_Flow_based_on_an_iterable_must_produce_elements_with_one_transformation_step ( )
244
241
{
245
- this . AssertAllStagesStopped ( ( ) =>
246
- {
247
- var p = CreateSource ( 3 )
248
- . Select ( x => x * 2 )
249
- . RunWith ( Sink . AsPublisher < int > ( false ) , Materializer ) ;
242
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
243
+ var p = CreateSource ( 3 )
244
+ . Select ( x => x * 2 )
245
+ . RunWith ( Sink . AsPublisher < int > ( false ) , Materializer ) ;
250
246
var c = this . CreateManualSubscriberProbe < int > ( ) ;
251
247
252
248
p . Subscribe ( c ) ;
253
- var sub = c . ExpectSubscription ( ) ;
249
+ var sub = await c . ExpectSubscriptionAsync ( ) ;
254
250
255
251
sub . Request ( 10 ) ;
256
- c . ExpectNext ( 2 )
252
+ await c . ExpectNext ( 2 )
257
253
. ExpectNext ( 4 )
258
254
. ExpectNext ( 6 )
259
- . ExpectComplete ( ) ;
255
+ . ExpectCompleteAsync ( ) ;
260
256
} , Materializer ) ;
261
257
}
262
258
263
259
[ Fact ]
264
- public void A_Flow_based_on_an_iterable_must_produce_elements_with_two_transformation_steps ( )
260
+ public async Task A_Flow_based_on_an_iterable_must_produce_elements_with_two_transformation_steps ( )
265
261
{
266
- this . AssertAllStagesStopped ( ( ) =>
267
- {
268
- var p = CreateSource ( 4 )
269
- . Where ( x => x % 2 == 0 )
270
- . Select ( x => x * 2 )
271
- . RunWith ( Sink . AsPublisher < int > ( false ) , Materializer ) ;
262
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
263
+ var p = CreateSource ( 4 )
264
+ . Where ( x => x % 2 == 0 )
265
+ . Select ( x => x * 2 )
266
+ . RunWith ( Sink . AsPublisher < int > ( false ) , Materializer ) ;
272
267
var c = this . CreateManualSubscriberProbe < int > ( ) ;
273
268
274
269
p . Subscribe ( c ) ;
275
- var sub = c . ExpectSubscription ( ) ;
270
+ var sub = await c . ExpectSubscriptionAsync ( ) ;
276
271
277
272
sub . Request ( 10 ) ;
278
- c . ExpectNext ( 4 )
273
+ await c . ExpectNext ( 4 )
279
274
. ExpectNext ( 8 )
280
- . ExpectComplete ( ) ;
275
+ . ExpectCompleteAsync ( ) ;
281
276
} , Materializer ) ;
282
277
}
283
278
284
279
[ Fact ]
285
- public void A_Flow_based_on_an_iterable_must_not_produce_after_cancel ( )
280
+ public async Task A_Flow_based_on_an_iterable_must_not_produce_after_cancel ( )
286
281
{
287
- this . AssertAllStagesStopped ( ( ) =>
288
- {
282
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
289
283
var p = CreateSource ( 3 ) . RunWith ( Sink . AsPublisher < int > ( false ) , Materializer ) ;
290
284
var c = this . CreateManualSubscriberProbe < int > ( ) ;
291
285
292
286
p . Subscribe ( c ) ;
293
- var sub = c . ExpectSubscription ( ) ;
287
+ var sub = await c . ExpectSubscriptionAsync ( ) ;
294
288
295
289
sub . Request ( 1 ) ;
296
- c . ExpectNext ( 1 ) ;
290
+ await c . ExpectNextAsync ( 1 ) ;
297
291
sub . Cancel ( ) ;
298
292
sub . Request ( 2 ) ;
299
- c . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 100 ) ) ;
293
+ await c . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 100 ) ) ;
300
294
} , Materializer ) ;
301
295
}
302
296
}
0 commit comments