@@ -44,53 +44,57 @@ private static Func<TMat> Fallback<TMat>()
44
44
private static readonly Exception Ex = new TestException ( "" ) ;
45
45
46
46
[ Fact ]
47
- public void A_LazySink_must_work_in_the_happy_case ( )
47
+ public async Task A_LazySink_must_work_in_the_happy_case ( )
48
48
{
49
- this . AssertAllStagesStopped ( async ( ) =>
49
+ await this . AssertAllStagesStoppedAsync ( async ( ) =>
50
50
{
51
51
var lazySink = Sink . LazyInitAsync ( ( ) => Task . FromResult ( this . SinkProbe < int > ( ) ) ) ;
52
52
var taskProbe = Source . From ( Enumerable . Range ( 0 , 11 ) ) . RunWith ( lazySink , Materializer ) ;
53
53
var probe = await taskProbe . ShouldCompleteWithin ( RemainingOrDefault ) ;
54
54
probe . Value . Request ( 100 ) ;
55
- Enumerable . Range ( 0 , 11 ) . ForEach ( i => probe . Value . ExpectNext ( i ) ) ;
55
+ foreach ( var i in Enumerable . Range ( 0 , 11 ) )
56
+ {
57
+ await probe . Value . ExpectNextAsync ( i ) ;
58
+ }
56
59
} , Materializer ) ;
57
60
}
58
61
59
62
[ Fact ]
60
- public void A_LazySink_must_work_with_slow_sink_init ( )
63
+ public async Task A_LazySink_must_work_with_slow_sink_init ( )
61
64
{
62
- this . AssertAllStagesStopped ( async ( ) =>
65
+ await this . AssertAllStagesStoppedAsync ( async ( ) =>
63
66
{
64
67
var p = new TaskCompletionSource < Sink < int , TestSubscriber . Probe < int > > > ( ) ;
65
68
var sourceProbe = this . CreateManualPublisherProbe < int > ( ) ;
66
69
var taskProbe = Source . FromPublisher ( sourceProbe )
67
70
. RunWith ( Sink . LazyInitAsync ( ( ) => p . Task ) , Materializer ) ;
68
71
69
- var sourceSub = sourceProbe . ExpectSubscription ( ) ;
70
- sourceSub . ExpectRequest ( 1 ) ;
72
+ var sourceSub = await sourceProbe . ExpectSubscriptionAsync ( ) ;
73
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
71
74
sourceSub . SendNext ( 0 ) ;
72
- sourceSub . ExpectRequest ( 1 ) ;
73
- sourceProbe . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 200 ) ) ;
75
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
76
+ await sourceProbe . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 200 ) ) ;
74
77
taskProbe . Wait ( TimeSpan . FromMilliseconds ( 200 ) ) . ShouldBeFalse ( ) ;
75
78
76
79
p . SetResult ( this . SinkProbe < int > ( ) ) ;
77
80
var complete = await taskProbe . ShouldCompleteWithin ( RemainingOrDefault ) ;
78
81
var probe = complete . Value ;
79
82
probe . Request ( 100 ) ;
80
- probe . ExpectNext ( 0 ) ;
81
- Enumerable . Range ( 1 , 10 ) . ForEach ( i =>
83
+ await probe . ExpectNextAsync ( 0 ) ;
84
+
85
+ foreach ( var i in Enumerable . Range ( 1 , 10 ) )
82
86
{
83
87
sourceSub . SendNext ( i ) ;
84
- probe . ExpectNext ( i ) ;
85
- } ) ;
88
+ await probe . ExpectNextAsync ( i ) ;
89
+ }
86
90
sourceSub . SendComplete ( ) ;
87
91
} , Materializer ) ;
88
92
}
89
93
90
94
[ Fact ]
91
- public void A_LazySink_must_complete_when_there_was_no_elements_in_stream ( )
95
+ public async Task A_LazySink_must_complete_when_there_was_no_elements_in_stream ( )
92
96
{
93
- this . AssertAllStagesStopped ( async ( ) =>
97
+ await this . AssertAllStagesStoppedAsync ( async ( ) =>
94
98
{
95
99
var lazySink = Sink . LazyInitAsync ( ( ) => Task . FromResult ( Sink . Aggregate ( 0 , ( int i , int i2 ) => i + i2 ) ) ) ;
96
100
var taskProbe = Source . Empty < int > ( ) . RunWith ( lazySink , Materializer ) ;
@@ -100,56 +104,55 @@ public void A_LazySink_must_complete_when_there_was_no_elements_in_stream()
100
104
}
101
105
102
106
[ Fact ]
103
- public void A_LazySink_must_complete_normally_when_upstream_is_completed ( )
107
+ public async Task A_LazySink_must_complete_normally_when_upstream_is_completed ( )
104
108
{
105
- this . AssertAllStagesStopped ( async ( ) =>
109
+ await this . AssertAllStagesStoppedAsync ( async ( ) =>
106
110
{
107
111
var lazySink = Sink . LazyInitAsync ( ( ) => Task . FromResult ( this . SinkProbe < int > ( ) ) ) ;
108
112
var taskProbe = Source . Single ( 1 ) . RunWith ( lazySink , Materializer ) ;
109
113
var taskResult = await taskProbe . ShouldCompleteWithin ( RemainingOrDefault ) ;
110
- taskResult . Value . Request ( 1 ) . ExpectNext ( 1 ) . ExpectComplete ( ) ;
114
+ await taskResult . Value . Request ( 1 ) . ExpectNext ( 1 ) . ExpectCompleteAsync ( ) ;
111
115
} , Materializer ) ;
112
116
}
113
117
114
118
[ Fact ]
115
- public void A_LazySink_must_fail_gracefully_when_sink_factory_method_failed ( )
119
+ public async Task A_LazySink_must_fail_gracefully_when_sink_factory_method_failed ( )
116
120
{
117
- this . AssertAllStagesStopped ( ( ) =>
118
- {
121
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
119
122
var sourceProbe = this . CreateManualPublisherProbe < int > ( ) ;
120
123
var taskProbe = Source . FromPublisher ( sourceProbe ) . RunWith ( Sink . LazyInitAsync < int , NotUsed > ( ( ) => throw Ex ) , Materializer ) ;
121
- var sourceSub = sourceProbe . ExpectSubscription ( ) ;
122
- sourceSub . ExpectRequest ( 1 ) ;
124
+ var sourceSub = await sourceProbe . ExpectSubscriptionAsync ( ) ;
125
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
123
126
sourceSub . SendNext ( 0 ) ;
124
- sourceSub . ExpectCancellation ( ) ;
127
+ await sourceSub . ExpectCancellationAsync ( ) ;
125
128
taskProbe . Invoking ( t => t . Wait ( ) ) . Should ( ) . Throw < TestException > ( ) ;
126
129
} , Materializer ) ;
127
130
}
128
131
129
132
[ Fact ]
130
- public void A_LazySink_must_fail_gracefully_when_upstream_failed ( )
133
+ public async Task A_LazySink_must_fail_gracefully_when_upstream_failed ( )
131
134
{
132
- this . AssertAllStagesStopped ( async ( ) =>
135
+ await this . AssertAllStagesStoppedAsync ( async ( ) =>
133
136
{
134
137
var sourceProbe = this . CreateManualPublisherProbe < int > ( ) ;
135
138
var lazySink = Sink . LazyInitAsync ( ( ) => Task . FromResult ( this . SinkProbe < int > ( ) ) ) ;
136
139
var taskProbe = Source . FromPublisher ( sourceProbe ) . RunWith ( lazySink , Materializer ) ;
137
140
138
- var sourceSub = sourceProbe . ExpectSubscription ( ) ;
139
- sourceSub . ExpectRequest ( 1 ) ;
141
+ var sourceSub = await sourceProbe . ExpectSubscriptionAsync ( ) ;
142
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
140
143
sourceSub . SendNext ( 0 ) ;
141
144
var complete = await taskProbe . ShouldCompleteWithin ( RemainingOrDefault ) ;
142
145
var probe = complete . Value ;
143
- probe . Request ( 1 ) . ExpectNext ( 0 ) ;
146
+ await probe . Request ( 1 ) . ExpectNextAsync ( 0 ) ;
144
147
sourceSub . SendError ( Ex ) ;
145
148
probe . ExpectError ( ) . Should ( ) . Be ( Ex ) ;
146
149
} , Materializer ) ;
147
150
}
148
151
149
152
[ Fact ]
150
- public void A_LazySink_must_fail_gracefully_when_factory_task_failed ( )
153
+ public async Task A_LazySink_must_fail_gracefully_when_factory_task_failed ( )
151
154
{
152
- this . AssertAllStagesStopped ( ( ) =>
155
+ await this . AssertAllStagesStoppedAsync ( async ( ) =>
153
156
{
154
157
var sourceProbe = this . CreateManualPublisherProbe < int > ( ) ;
155
158
var lazySink = Sink . LazyInitAsync ( ( ) => Task . FromException < Sink < int , TestSubscriber . Probe < int > > > ( Ex ) ) ;
@@ -159,38 +162,38 @@ public void A_LazySink_must_fail_gracefully_when_factory_task_failed()
159
162
. WithAttributes ( ActorAttributes . CreateSupervisionStrategy ( Deciders . StoppingDecider ) )
160
163
. Run ( Materializer ) ;
161
164
162
- var sourceSub = sourceProbe . ExpectSubscription ( ) ;
163
- sourceSub . ExpectRequest ( 1 ) ;
165
+ var sourceSub = await sourceProbe . ExpectSubscriptionAsync ( ) ;
166
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
164
167
sourceSub . SendNext ( 0 ) ;
165
168
taskProbe . Invoking ( t => t . Wait ( TimeSpan . FromMilliseconds ( 300 ) ) ) . Should ( ) . Throw < TestException > ( ) ;
169
+
166
170
} , Materializer ) ;
167
171
}
168
172
169
173
[ Fact ]
170
- public void A_LazySink_must_cancel_upstream_when_internal_sink_is_cancelled ( )
174
+ public async Task A_LazySink_must_cancel_upstream_when_internal_sink_is_cancelled ( )
171
175
{
172
- this . AssertAllStagesStopped ( async ( ) =>
176
+ await this . AssertAllStagesStoppedAsync ( async ( ) =>
173
177
{
174
178
var sourceProbe = this . CreateManualPublisherProbe < int > ( ) ;
175
179
var lazySink = Sink . LazyInitAsync ( ( ) => Task . FromResult ( this . SinkProbe < int > ( ) ) ) ;
176
180
var taskProbe = Source . FromPublisher ( sourceProbe ) . RunWith ( lazySink , Materializer ) ;
177
- var sourceSub = sourceProbe . ExpectSubscription ( ) ;
178
- sourceSub . ExpectRequest ( 1 ) ;
181
+ var sourceSub = await sourceProbe . ExpectSubscriptionAsync ( ) ;
182
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
179
183
sourceSub . SendNext ( 0 ) ;
180
- sourceSub . ExpectRequest ( 1 ) ;
184
+ await sourceSub . ExpectRequestAsync ( 1 ) ;
181
185
var complete = await taskProbe . ShouldCompleteWithin ( RemainingOrDefault ) ;
182
186
var probe = complete . Value ;
183
- probe . Request ( 1 ) . ExpectNext ( 0 ) ;
187
+ await probe . Request ( 1 ) . ExpectNextAsync ( 0 ) ;
184
188
probe . Cancel ( ) ;
185
- sourceSub . ExpectCancellation ( ) ;
189
+ await sourceSub . ExpectCancellationAsync ( ) ;
186
190
} , Materializer ) ;
187
191
}
188
192
189
193
[ Fact ]
190
- public void A_LazySink_must_fail_correctly_when_materialization_of_inner_sink_fails ( )
194
+ public async Task A_LazySink_must_fail_correctly_when_materialization_of_inner_sink_fails ( )
191
195
{
192
- this . AssertAllStagesStopped ( ( ) =>
193
- {
196
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
194
197
var matFail = new TestException ( "fail!" ) ;
195
198
196
199
var task = Source . Single ( "whatever" )
@@ -205,7 +208,7 @@ public void A_LazySink_must_fail_correctly_when_materialization_of_inner_sink_fa
205
208
task . IsFaulted . ShouldBe ( true ) ;
206
209
task . Exception . ShouldNotBe ( null ) ;
207
210
task . Exception . Flatten ( ) . InnerException . Should ( ) . BeEquivalentTo ( matFail ) ;
208
-
211
+ return Task . CompletedTask ;
209
212
} , Materializer ) ;
210
213
}
211
214
0 commit comments