@@ -37,30 +37,28 @@ public InputStreamSinkSpec(ITestOutputHelper helper) : base(Utils.UnboundedMailb
37
37
}
38
38
39
39
[ Fact ]
40
- public void InputStreamSink_should_read_bytes_from_input_stream ( )
40
+ public async Task InputStreamSink_should_read_bytes_from_input_stream ( )
41
41
{
42
- this . AssertAllStagesStopped ( ( ) =>
43
- {
42
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
44
43
var inputStream = Source . Single ( _byteString ) . RunWith ( StreamConverters . AsInputStream ( ) , _materializer ) ;
45
44
var result = ReadN ( inputStream , _byteString . Count ) ;
46
45
inputStream . Dispose ( ) ;
47
46
result . Item1 . Should ( ) . Be ( _byteString . Count ) ;
48
47
result . Item2 . Should ( ) . BeEquivalentTo ( _byteString ) ;
49
-
48
+ return Task . CompletedTask ;
50
49
} , _materializer ) ;
51
50
}
52
51
53
52
[ Fact ]
54
- public void InputStreamSink_should_read_bytes_correctly_if_requested_by_input_stream_not_in_chunk_size ( )
53
+ public async Task InputStreamSink_should_read_bytes_correctly_if_requested_by_input_stream_not_in_chunk_size ( )
55
54
{
56
- this . AssertAllStagesStopped ( ( ) =>
57
- {
55
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
58
56
var sinkProbe = CreateTestProbe ( ) ;
59
57
var byteString2 = RandomByteString ( 3 ) ;
60
58
var inputStream = Source . From ( new [ ] { _byteString , byteString2 , null } )
61
59
. RunWith ( TestSink ( sinkProbe ) , _materializer ) ;
62
60
63
- sinkProbe . ExpectMsgAllOf ( new [ ] { GraphStageMessages . Push . Instance , GraphStageMessages . Push . Instance } ) ;
61
+ sinkProbe . ExpectMsgAllOf ( new [ ] { GraphStageMessages . Push . Instance , GraphStageMessages . Push . Instance } ) ;
64
62
65
63
var result = ReadN ( inputStream , 2 ) ;
66
64
result . Item1 . Should ( ) . Be ( 2 ) ;
@@ -75,34 +73,32 @@ public void InputStreamSink_should_read_bytes_correctly_if_requested_by_input_st
75
73
result . Item2 . Should ( ) . BeEquivalentTo ( byteString2 . Slice ( 1 ) ) ;
76
74
77
75
inputStream . Dispose ( ) ;
78
-
76
+ return Task . CompletedTask ;
79
77
} , _materializer ) ;
80
78
}
81
79
82
80
[ Fact ]
83
- public void InputStreamSink_should_return_less_than_was_expected_when_data_source_has_provided_some_but_not_enough_data ( )
81
+ public async Task InputStreamSink_should_return_less_than_was_expected_when_data_source_has_provided_some_but_not_enough_data ( )
84
82
{
85
- this . AssertAllStagesStopped ( ( ) =>
86
- {
83
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
87
84
var inputStream = Source . Single ( _byteString ) . RunWith ( StreamConverters . AsInputStream ( ) , _materializer ) ;
88
85
89
86
var arr = new byte [ _byteString . Count + 1 ] ;
90
87
inputStream . Read ( arr , 0 , arr . Length ) . Should ( ) . Be ( arr . Length - 1 ) ;
91
88
inputStream . Dispose ( ) ;
92
89
ByteString . FromBytes ( arr ) . Should ( ) . BeEquivalentTo ( Enumerable . Concat ( _byteString , ByteString . FromBytes ( new byte [ ] { 0 } ) ) ) ;
93
-
90
+ return Task . CompletedTask ;
94
91
} , _materializer ) ;
95
92
}
96
93
97
94
[ WindowsFact ( Skip = "Racy in Linux" ) ]
98
- public void InputStreamSink_should_block_read_until_get_requested_number_of_bytes_from_upstream ( )
95
+ public async Task InputStreamSink_should_block_read_until_get_requested_number_of_bytes_from_upstream ( )
99
96
{
100
- this . AssertAllStagesStopped ( ( ) =>
101
- {
102
- var run =
103
- this . SourceProbe < ByteString > ( )
104
- . ToMaterialized ( StreamConverters . AsInputStream ( ) , Keep . Both )
105
- . Run ( _materializer ) ;
97
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
98
+ var run =
99
+ this . SourceProbe < ByteString > ( )
100
+ . ToMaterialized ( StreamConverters . AsInputStream ( ) , Keep . Both )
101
+ . Run ( _materializer ) ;
106
102
var probe = run . Item1 ;
107
103
var inputStream = run . Item2 ;
108
104
var f = Task . Run ( ( ) => inputStream . Read ( new byte [ _byteString . Count ] , 0 , _byteString . Count ) ) ;
@@ -116,18 +112,17 @@ public void InputStreamSink_should_block_read_until_get_requested_number_of_byte
116
112
probe . SendComplete ( ) ;
117
113
inputStream . ReadByte ( ) . Should ( ) . Be ( - 1 ) ;
118
114
inputStream . Dispose ( ) ;
119
-
115
+ return Task . CompletedTask ;
120
116
} , _materializer ) ;
121
117
}
122
118
123
119
[ Fact ]
124
- public void InputStreamSink_should_throw_error_when_reactive_stream_is_closed ( )
120
+ public async Task InputStreamSink_should_throw_error_when_reactive_stream_is_closed ( )
125
121
{
126
- this . AssertAllStagesStopped ( ( ) =>
127
- {
128
- var t = this . SourceProbe < ByteString > ( )
129
- . ToMaterialized ( StreamConverters . AsInputStream ( ) , Keep . Both )
130
- . Run ( _materializer ) ;
122
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
123
+ var t = this . SourceProbe < ByteString > ( )
124
+ . ToMaterialized ( StreamConverters . AsInputStream ( ) , Keep . Both )
125
+ . Run ( _materializer ) ;
131
126
var probe = t . Item1 ;
132
127
var inputStream = t . Item2 ;
133
128
@@ -137,14 +132,14 @@ public void InputStreamSink_should_throw_error_when_reactive_stream_is_closed()
137
132
138
133
Action block = ( ) => inputStream . Read ( new byte [ 1 ] , 0 , 1 ) ;
139
134
block . Should ( ) . Throw < IOException > ( ) ;
135
+ return Task . CompletedTask ;
140
136
} , _materializer ) ;
141
137
}
142
138
143
139
[ Fact ]
144
- public void InputStreamSink_should_return_all_data_when_upstream_is_completed ( )
140
+ public async Task InputStreamSink_should_return_all_data_when_upstream_is_completed ( )
145
141
{
146
- this . AssertAllStagesStopped ( ( ) =>
147
- {
142
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
148
143
var sinkProbe = CreateTestProbe ( ) ;
149
144
var t = this . SourceProbe < ByteString > ( ) . ToMaterialized ( TestSink ( sinkProbe ) , Keep . Both ) . Run ( _materializer ) ;
150
145
var probe = t . Item1 ;
@@ -160,14 +155,14 @@ public void InputStreamSink_should_return_all_data_when_upstream_is_completed()
160
155
var result = ReadN ( inputStream , 3 ) ;
161
156
result . Item1 . Should ( ) . Be ( 1 ) ;
162
157
result . Item2 . Should ( ) . BeEquivalentTo ( bytes ) ;
158
+ return Task . CompletedTask ;
163
159
} , _materializer ) ;
164
160
}
165
161
166
162
[ Fact ]
167
- public void InputStreamSink_should_work_when_read_chunks_smaller_then_stream_chunks ( )
163
+ public async Task InputStreamSink_should_work_when_read_chunks_smaller_then_stream_chunks ( )
168
164
{
169
- this . AssertAllStagesStopped ( ( ) =>
170
- {
165
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
171
166
var bytes = RandomByteString ( 10 ) ;
172
167
var inputStream = Source . Single ( bytes ) . RunWith ( StreamConverters . AsInputStream ( ) , _materializer ) ;
173
168
@@ -182,31 +177,31 @@ public void InputStreamSink_should_work_when_read_chunks_smaller_then_stream_chu
182
177
}
183
178
184
179
inputStream . Dispose ( ) ;
180
+ return Task . CompletedTask ;
185
181
} , _materializer ) ;
186
182
}
187
183
188
184
[ Fact ]
189
- public void InputStreamSink_should_throw_exception_when_call_read_With_wrong_parameters ( )
185
+ public async Task InputStreamSink_should_throw_exception_when_call_read_With_wrong_parameters ( )
190
186
{
191
- this . AssertAllStagesStopped ( ( ) =>
192
- {
187
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
193
188
var inputStream = Source . Single ( _byteString ) . RunWith ( StreamConverters . AsInputStream ( ) , _materializer ) ;
194
189
var buf = new byte [ 3 ] ;
195
190
196
191
Action ( ( ) => inputStream . Read ( buf , - 1 , 2 ) ) . Should ( ) . Throw < ArgumentException > ( ) ;
197
192
Action ( ( ) => inputStream . Read ( buf , 0 , 5 ) ) . Should ( ) . Throw < ArgumentException > ( ) ;
198
193
Action ( ( ) => inputStream . Read ( new byte [ 0 ] , 0 , 1 ) ) . Should ( ) . Throw < ArgumentException > ( ) ;
199
194
Action ( ( ) => inputStream . Read ( buf , 0 , 0 ) ) . Should ( ) . Throw < ArgumentException > ( ) ;
195
+ return Task . CompletedTask ;
200
196
} , _materializer ) ;
201
197
}
202
198
203
199
private Action Action ( Action a ) => a ;
204
200
205
201
[ Fact ]
206
- public void InputStreamSink_should_successfully_read_several_chunks_at_once ( )
202
+ public async Task InputStreamSink_should_successfully_read_several_chunks_at_once ( )
207
203
{
208
- this . AssertAllStagesStopped ( ( ) =>
209
- {
204
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
210
205
var bytes = Enumerable . Range ( 1 , 4 ) . Select ( _ => RandomByteString ( 4 ) ) . ToList ( ) ;
211
206
var sinkProbe = CreateTestProbe ( ) ;
212
207
var inputStream = Source . From ( bytes ) . RunWith ( TestSink ( sinkProbe ) , _materializer ) ;
@@ -222,21 +217,21 @@ public void InputStreamSink_should_successfully_read_several_chunks_at_once()
222
217
}
223
218
224
219
inputStream . Dispose ( ) ;
220
+ return Task . CompletedTask ;
225
221
} , _materializer ) ;
226
222
}
227
223
228
224
[ Fact ]
229
- public void InputStreamSink_should_work_when_read_chunks_bigger_than_stream_chunks ( )
225
+ public async Task InputStreamSink_should_work_when_read_chunks_bigger_than_stream_chunks ( )
230
226
{
231
- this . AssertAllStagesStopped ( ( ) =>
232
- {
227
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
233
228
var bytes1 = RandomByteString ( 10 ) ;
234
229
var bytes2 = RandomByteString ( 10 ) ;
235
230
var sinkProbe = CreateTestProbe ( ) ;
236
231
var inputStream = Source . From ( new [ ] { bytes1 , bytes2 , null } ) . RunWith ( TestSink ( sinkProbe ) , _materializer ) ;
237
232
238
233
//need to wait while both elements arrive to sink
239
- sinkProbe . ExpectMsgAllOf ( new [ ] { GraphStageMessages . Push . Instance , GraphStageMessages . Push . Instance } ) ;
234
+ sinkProbe . ExpectMsgAllOf ( new [ ] { GraphStageMessages . Push . Instance , GraphStageMessages . Push . Instance } ) ;
240
235
241
236
var r1 = ReadN ( inputStream , 15 ) ;
242
237
r1 . Item1 . Should ( ) . Be ( 15 ) ;
@@ -247,14 +242,14 @@ public void InputStreamSink_should_work_when_read_chunks_bigger_than_stream_chun
247
242
r2 . Item2 . Should ( ) . BeEquivalentTo ( bytes2 . Slice ( 5 ) ) ;
248
243
249
244
inputStream . Dispose ( ) ;
245
+ return Task . CompletedTask ;
250
246
} , _materializer ) ;
251
247
}
252
248
253
249
[ Fact ]
254
- public void InputStreamSink_should_return_minus_1_when_read_after_stream_is_completed ( )
250
+ public async Task InputStreamSink_should_return_minus_1_when_read_after_stream_is_completed ( )
255
251
{
256
- this . AssertAllStagesStopped ( ( ) =>
257
- {
252
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
258
253
var inputStream = Source . Single ( _byteString ) . RunWith ( StreamConverters . AsInputStream ( ) , _materializer ) ;
259
254
260
255
var r = ReadN ( inputStream , _byteString . Count ) ;
@@ -263,14 +258,14 @@ public void InputStreamSink_should_return_minus_1_when_read_after_stream_is_comp
263
258
264
259
inputStream . ReadByte ( ) . Should ( ) . Be ( - 1 ) ;
265
260
inputStream . Dispose ( ) ;
261
+ return Task . CompletedTask ;
266
262
} , _materializer ) ;
267
263
}
268
264
269
265
[ Fact ]
270
- public void InputStreamSink_should_return_Exception_when_stream_is_failed ( )
266
+ public async Task InputStreamSink_should_return_Exception_when_stream_is_failed ( )
271
267
{
272
- this . AssertAllStagesStopped ( ( ) =>
273
- {
268
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
274
269
var sinkProbe = CreateTestProbe ( ) ;
275
270
var t = this . SourceProbe < ByteString > ( ) . ToMaterialized ( TestSink ( sinkProbe ) , Keep . Both ) . Run ( _materializer ) ;
276
271
var probe = t . Item1 ;
@@ -293,15 +288,14 @@ public void InputStreamSink_should_return_Exception_when_stream_is_failed()
293
288
block . Should ( ) . Throw < Exception > ( ) ;
294
289
295
290
task . Exception . InnerException . Should ( ) . Be ( ex ) ;
296
-
291
+ return Task . CompletedTask ;
297
292
} , _materializer ) ;
298
293
}
299
294
300
295
[ Fact ]
301
- public void InputStreamSink_should_use_dedicated_default_blocking_io_dispatcher_by_default ( )
296
+ public async Task InputStreamSink_should_use_dedicated_default_blocking_io_dispatcher_by_default ( )
302
297
{
303
- this . AssertAllStagesStopped ( ( ) =>
304
- {
298
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
305
299
var sys = ActorSystem . Create ( "InputStreamSink-testing" , Utils . UnboundedMailboxConfig ) ;
306
300
var materializer = ActorMaterializer . Create ( sys ) ;
307
301
try
@@ -316,30 +310,31 @@ public void InputStreamSink_should_use_dedicated_default_blocking_io_dispatcher_
316
310
{
317
311
Shutdown ( sys ) ;
318
312
}
313
+
314
+ return Task . CompletedTask ;
319
315
} , _materializer ) ;
320
316
}
321
317
322
318
[ Fact ]
323
- public void InputStreamSink_should_work_when_more_bytes_pulled_from_input_stream_than_available ( )
319
+ public async Task InputStreamSink_should_work_when_more_bytes_pulled_from_input_stream_than_available ( )
324
320
{
325
- this . AssertAllStagesStopped ( ( ) =>
326
- {
321
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
327
322
var inputStream = Source . Single ( _byteString ) . RunWith ( StreamConverters . AsInputStream ( ) , _materializer ) ;
328
323
329
324
var r = ReadN ( inputStream , _byteString . Count * 2 ) ;
330
325
r . Item1 . Should ( ) . Be ( _byteString . Count ) ;
331
326
r . Item2 . Should ( ) . BeEquivalentTo ( _byteString ) ;
332
327
333
328
inputStream . Dispose ( ) ;
329
+ return Task . CompletedTask ;
334
330
} , _materializer ) ;
335
331
}
336
332
337
333
338
334
[ Fact ]
339
- public void InputStreamSink_should_read_next_byte_as_an_int_from_InputStream ( )
335
+ public async Task InputStreamSink_should_read_next_byte_as_an_int_from_InputStream ( )
340
336
{
341
- this . AssertAllStagesStopped ( ( ) =>
342
- {
337
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
343
338
var bytes = ByteString . CopyFrom ( new byte [ ] { 0 , 100 , 200 , 255 } ) ;
344
339
var inputStream = Source . Single ( bytes ) . RunWith ( StreamConverters . AsInputStream ( ) , _materializer ) ;
345
340
@@ -348,6 +343,7 @@ public void InputStreamSink_should_read_next_byte_as_an_int_from_InputStream()
348
343
. Should ( ) . BeEquivalentTo ( new [ ] { 0 , 100 , 200 , 255 , - 1 } ) ;
349
344
350
345
inputStream . Dispose ( ) ;
346
+ return Task . CompletedTask ;
351
347
} , _materializer ) ;
352
348
}
353
349
0 commit comments