19
19
using System . Threading ;
20
20
using Akka . Streams . TestKit ;
21
21
using Akka . TestKit . Xunit2 . Attributes ;
22
+ using System . Threading . Tasks ;
22
23
23
24
namespace Akka . Streams . Tests . Dsl
24
25
{
@@ -33,76 +34,76 @@ public SinkForeachParallelSpec(ITestOutputHelper helper) : base(helper)
33
34
}
34
35
35
36
[ LocalFact ( SkipLocal = "Racy due to timing on Azure DevOps" ) ]
36
- public void A_ForeachParallel_must_produce_elements_in_the_order_they_are_ready ( )
37
+ public async Task A_ForeachParallel_must_produce_elements_in_the_order_they_are_ready ( )
37
38
{
38
- this . AssertAllStagesStopped ( ( ) =>
39
- {
39
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
40
40
var probe = CreateTestProbe ( ) ;
41
41
var latch = Enumerable . Range ( 1 , 4 )
42
42
. Select ( i => ( i , new TestLatch ( 1 ) ) )
43
43
. ToDictionary ( t => t . Item1 , t => t . Item2 ) ;
44
+ #pragma warning disable CS0618 // Type or member is obsolete
44
45
var p = Source . From ( Enumerable . Range ( 1 , 4 ) ) . RunWith ( Sink . ForEachParallel < int > ( 4 , n =>
45
46
{
46
47
latch [ n ] . Ready ( TimeSpan . FromSeconds ( 5 ) ) ;
47
48
probe . Ref . Tell ( n ) ;
48
49
} ) , Materializer ) ;
50
+ #pragma warning restore CS0618 // Type or member is obsolete
49
51
latch [ 2 ] . CountDown ( ) ;
50
- probe . ExpectMsg ( 2 , TimeSpan . FromSeconds ( 5 ) ) ;
52
+ await probe . ExpectMsgAsync ( 2 , TimeSpan . FromSeconds ( 5 ) ) ;
51
53
latch [ 4 ] . CountDown ( ) ;
52
- probe . ExpectMsg ( 4 , TimeSpan . FromSeconds ( 5 ) ) ;
54
+ await probe . ExpectMsgAsync ( 4 , TimeSpan . FromSeconds ( 5 ) ) ;
53
55
latch [ 3 ] . CountDown ( ) ;
54
- probe . ExpectMsg ( 3 , TimeSpan . FromSeconds ( 5 ) ) ;
56
+ await probe . ExpectMsgAsync ( 3 , TimeSpan . FromSeconds ( 5 ) ) ;
55
57
56
58
p . IsCompleted . Should ( ) . BeFalse ( ) ;
57
59
58
60
latch [ 1 ] . CountDown ( ) ;
59
- probe . ExpectMsg ( 1 , TimeSpan . FromSeconds ( 5 ) ) ;
61
+ await probe . ExpectMsgAsync ( 1 , TimeSpan . FromSeconds ( 5 ) ) ;
60
62
61
63
p . Wait ( TimeSpan . FromSeconds ( 4 ) ) . Should ( ) . BeTrue ( ) ;
62
64
p . IsCompleted . Should ( ) . BeTrue ( ) ;
63
-
64
65
} , Materializer ) ;
65
66
}
66
67
67
68
[ LocalFact ( SkipLocal = "Racy - timing is rather sensitive on Azure DevOps" ) ]
68
- public void A_ForeachParallel_must_not_run_more_functions_in_parallel_then_specified ( )
69
+ public async Task A_ForeachParallel_must_not_run_more_functions_in_parallel_then_specified ( )
69
70
{
70
- this . AssertAllStagesStopped ( ( ) =>
71
- {
71
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
72
72
var probe = CreateTestProbe ( ) ;
73
73
var latch = Enumerable . Range ( 1 , 5 )
74
74
. Select ( i => ( i , new TestLatch ( ) ) )
75
75
. ToDictionary ( t => t . Item1 , t => t . Item2 ) ;
76
+ #pragma warning disable CS0618 // Type or member is obsolete
76
77
var p = Source . From ( Enumerable . Range ( 1 , 5 ) ) . RunWith ( Sink . ForEachParallel < int > ( 4 , n =>
77
78
{
78
79
probe . Ref . Tell ( n ) ;
79
80
latch [ n ] . Ready ( TimeSpan . FromSeconds ( 5 ) ) ;
80
81
} ) , Materializer ) ;
82
+ #pragma warning restore CS0618 // Type or member is obsolete
81
83
82
- probe . ExpectMsgAllOf ( new [ ] { 1 , 2 , 3 , 4 } ) ;
83
- probe . ExpectNoMsg ( TimeSpan . FromMilliseconds ( 200 ) ) ;
84
+ probe . ExpectMsgAllOf ( new [ ] { 1 , 2 , 3 , 4 } ) ;
85
+ await probe . ExpectNoMsgAsync ( TimeSpan . FromMilliseconds ( 200 ) ) ;
84
86
85
87
p . IsCompleted . Should ( ) . BeFalse ( ) ;
86
-
88
+
87
89
Enumerable . Range ( 1 , 4 ) . ForEach ( i => latch [ i ] . CountDown ( ) ) ;
88
90
89
91
latch [ 5 ] . CountDown ( ) ;
90
- probe . ExpectMsg ( 5 ) ;
92
+ await probe . ExpectMsgAsync ( 5 ) ;
91
93
92
94
p . Wait ( TimeSpan . FromSeconds ( 5 ) ) . Should ( ) . BeTrue ( ) ;
93
95
p . IsCompleted . Should ( ) . BeTrue ( ) ;
94
-
95
96
} , Materializer ) ;
96
97
}
97
98
98
99
[ Fact ]
99
- public void A_ForeachParallel_must_resume_after_function_failure ( )
100
+ public async Task A_ForeachParallel_must_resume_after_function_failure ( )
100
101
{
101
- this . AssertAllStagesStopped ( ( ) =>
102
- {
102
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
103
103
var probe = CreateTestProbe ( ) ;
104
104
var latch = new TestLatch ( 1 ) ;
105
105
106
+ #pragma warning disable CS0618 // Type or member is obsolete
106
107
var p = Source . From ( Enumerable . Range ( 1 , 5 ) ) . RunWith ( Sink . ForEachParallel < int > ( 4 , n =>
107
108
{
108
109
if ( n == 3 )
@@ -111,22 +112,24 @@ public void A_ForeachParallel_must_resume_after_function_failure()
111
112
probe . Ref . Tell ( n ) ;
112
113
latch . Ready ( TimeSpan . FromSeconds ( 10 ) ) ;
113
114
} ) . WithAttributes ( ActorAttributes . CreateSupervisionStrategy ( Deciders . ResumingDecider ) ) , Materializer ) ;
115
+ #pragma warning restore CS0618 // Type or member is obsolete
114
116
115
117
latch . CountDown ( ) ;
116
- probe . ExpectMsgAllOf ( new [ ] { 1 , 2 , 4 , 5 } ) ;
118
+ probe . ExpectMsgAllOf ( new [ ] { 1 , 2 , 4 , 5 } ) ;
117
119
118
120
p . Wait ( TimeSpan . FromSeconds ( 5 ) ) . Should ( ) . BeTrue ( ) ;
121
+ return Task . CompletedTask ;
119
122
} , Materializer ) ;
120
123
}
121
124
122
125
[ Fact ]
123
- public void A_ForeachParallel_must_finish_after_function_thrown_exception ( )
126
+ public async Task A_ForeachParallel_must_finish_after_function_thrown_exception ( )
124
127
{
125
- this . AssertAllStagesStopped ( ( ) =>
126
- {
128
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
127
129
var probe = CreateTestProbe ( ) ;
128
130
var latch = new TestLatch ( 1 ) ;
129
131
132
+ #pragma warning disable CS0618 // Type or member is obsolete
130
133
var p = Source . From ( Enumerable . Range ( 1 , 5 ) ) . RunWith ( Sink . ForEachParallel < int > ( 3 , n =>
131
134
{
132
135
if ( n == 3 )
@@ -135,11 +138,12 @@ public void A_ForeachParallel_must_finish_after_function_thrown_exception()
135
138
probe . Ref . Tell ( n ) ;
136
139
latch . Ready ( TimeSpan . FromSeconds ( 10 ) ) ;
137
140
} ) . WithAttributes ( ActorAttributes . CreateSupervisionStrategy ( Deciders . StoppingDecider ) ) , Materializer ) ;
138
-
141
+ #pragma warning restore CS0618 // Type or member is obsolete
142
+
139
143
// make sure the stream is up and running, otherwise the latch is maybe ready before the third message arrives
140
- Thread . Sleep ( 500 ) ;
144
+ await Task . Delay ( 500 ) ;
141
145
latch . CountDown ( ) ;
142
- probe . ExpectMsgAllOf ( new [ ] { 1 , 2 } ) ;
146
+ probe . ExpectMsgAllOf ( new [ ] { 1 , 2 } ) ;
143
147
144
148
var ex = p . Invoking ( t => t . Wait ( TimeSpan . FromSeconds ( 1 ) ) ) . Should ( ) . Throw < AggregateException > ( ) . Which ;
145
149
ex . Flatten ( ) . InnerException . Should ( ) . BeOfType < TestException > ( ) ;
@@ -150,12 +154,14 @@ public void A_ForeachParallel_must_finish_after_function_thrown_exception()
150
154
}
151
155
152
156
[ Fact ]
153
- public void A_ForeachParallel_must_handle_empty_source ( )
157
+ public async Task A_ForeachParallel_must_handle_empty_source ( )
154
158
{
155
- this . AssertAllStagesStopped ( ( ) =>
156
- {
159
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
160
+ #pragma warning disable CS0618 // Type or member is obsolete
157
161
var p = Source . From ( new List < int > ( ) ) . RunWith ( Sink . ForEachParallel < int > ( 3 , i => { } ) , Materializer ) ;
162
+ #pragma warning restore CS0618 // Type or member is obsolete
158
163
p . Wait ( TimeSpan . FromSeconds ( 2 ) ) . Should ( ) . BeTrue ( ) ;
164
+ return Task . CompletedTask ;
159
165
} , Materializer ) ;
160
166
}
161
167
}
0 commit comments