6
6
//-----------------------------------------------------------------------
7
7
8
8
using System ;
9
- using System . Collections . Generic ;
9
+ using System . Threading . Tasks ;
10
10
using Akka . Actor ;
11
11
using Akka . Streams . Actors ;
12
12
using Akka . Streams . Dsl ;
13
13
using Akka . Streams . TestKit ;
14
14
using Akka . TestKit ;
15
15
using Akka . TestKit . Xunit2 . Attributes ;
16
- using FluentAssertions . Execution ;
17
16
using Xunit ;
18
17
using Xunit . Abstractions ;
19
18
@@ -37,10 +36,10 @@ public TestObserver(AkkaSpec spec)
37
36
public void OnError ( Exception error ) => _probe . Ref . Tell ( new OnError ( error ) , ActorRefs . NoSender ) ;
38
37
public void OnCompleted ( ) => _probe . Ref . Tell ( OnComplete . Instance , ActorRefs . NoSender ) ;
39
38
40
- public T ExpectEvent ( T expected ) => ( T ) _probe . ExpectMsg < OnNext > ( x => Equals ( x . Element , expected ) ) . Element ;
41
- public TError ExpectError < TError > ( TError error ) where TError : Exception => ( TError ) _probe . ExpectMsg < OnError > ( x => Equals ( x . Cause , error ) ) . Cause ;
42
- public void ExpectCompleted ( ) => _probe . ExpectMsg < OnComplete > ( ) ;
43
- public void ExpectNoMsg ( ) => _probe . ExpectNoMsg ( ) ;
39
+ public async Task < T > ExpectEventAsync ( T expected ) => ( T ) ( await _probe . ExpectMsgAsync < OnNext > ( x => Equals ( x . Element , expected ) ) ) . Element ;
40
+ public async Task < TError > ExpectErrorAsync < TError > ( TError error ) where TError : Exception => ( TError ) ( await _probe . ExpectMsgAsync < OnError > ( x => Equals ( x . Cause , error ) ) ) . Cause ;
41
+ public async Task ExpectCompletedAsync ( ) => await _probe . ExpectMsgAsync < OnComplete > ( ) ;
42
+ public async Task ExpectNoMsgAsync ( ) => await _probe . ExpectNoMsgAsync ( ) ;
44
43
}
45
44
46
45
#endregion
@@ -55,10 +54,9 @@ public ObservableSinkSpec(ITestOutputHelper helper) : base(SpecConfig, helper)
55
54
}
56
55
57
56
[ LocalFact ( SkipLocal = "Racy on Azure DevOps" ) ]
58
- public void An_ObservableSink_must_allow_the_same_observer_to_be_subscribed_only_once ( )
57
+ public async Task An_ObservableSink_must_allow_the_same_observer_to_be_subscribed_only_once ( )
59
58
{
60
- this . AssertAllStagesStopped ( ( ) =>
61
- {
59
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
62
60
var probe = new TestObserver < int > ( this ) ;
63
61
var observable = Source . From ( new [ ] { 1 , 2 , 3 } )
64
62
. RunWith ( Sink . AsObservable < int > ( ) , Materializer ) ;
@@ -68,20 +66,18 @@ public void An_ObservableSink_must_allow_the_same_observer_to_be_subscribed_only
68
66
69
67
d1 . ShouldBe ( d2 ) ;
70
68
71
- probe . ExpectEvent ( 1 ) ;
72
- probe . ExpectEvent ( 2 ) ;
73
- probe . ExpectEvent ( 3 ) ;
74
- probe . ExpectCompleted ( ) ;
75
- probe . ExpectNoMsg ( ) ;
76
-
69
+ await probe . ExpectEventAsync ( 1 ) ;
70
+ await probe . ExpectEventAsync ( 2 ) ;
71
+ await probe . ExpectEventAsync ( 3 ) ;
72
+ await probe . ExpectCompletedAsync ( ) ;
73
+ await probe . ExpectNoMsgAsync ( ) ;
77
74
} , Materializer ) ;
78
75
}
79
76
80
77
[ LocalFact ( SkipLocal = "Racy on Azure DevOps" ) ]
81
- public void An_ObservableSink_must_propagate_events_to_all_observers ( )
78
+ public async Task An_ObservableSink_must_propagate_events_to_all_observers ( )
82
79
{
83
- this . AssertAllStagesStopped ( ( ) =>
84
- {
80
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
85
81
var probe1 = new TestObserver < int > ( this ) ;
86
82
var probe2 = new TestObserver < int > ( this ) ;
87
83
var observable = Source . From ( new [ ] { 1 , 2 } )
@@ -90,24 +86,22 @@ public void An_ObservableSink_must_propagate_events_to_all_observers()
90
86
var d1 = observable . Subscribe ( probe1 ) ;
91
87
var d2 = observable . Subscribe ( probe2 ) ;
92
88
93
- probe1 . ExpectEvent ( 1 ) ;
94
- probe1 . ExpectEvent ( 2 ) ;
95
- probe1 . ExpectCompleted ( ) ;
96
- probe1 . ExpectNoMsg ( ) ;
97
-
98
- probe2 . ExpectEvent ( 1 ) ;
99
- probe2 . ExpectEvent ( 2 ) ;
100
- probe2 . ExpectCompleted ( ) ;
101
- probe2 . ExpectNoMsg ( ) ;
89
+ await probe1 . ExpectEventAsync ( 1 ) ;
90
+ await probe1 . ExpectEventAsync ( 2 ) ;
91
+ await probe1 . ExpectCompletedAsync ( ) ;
92
+ await probe1 . ExpectNoMsgAsync ( ) ;
102
93
94
+ await probe2 . ExpectEventAsync ( 1 ) ;
95
+ await probe2 . ExpectEventAsync ( 2 ) ;
96
+ await probe2 . ExpectCompletedAsync ( ) ;
97
+ await probe2 . ExpectNoMsgAsync ( ) ;
103
98
} , Materializer ) ;
104
99
}
105
100
106
101
[ LocalFact ( SkipLocal = "Racy on Azure DevOps" ) ]
107
- public void An_ObservableSink_must_propagate_error_to_all_observers ( )
102
+ public async Task An_ObservableSink_must_propagate_error_to_all_observers ( )
108
103
{
109
- this . AssertAllStagesStopped ( ( ) =>
110
- {
104
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
111
105
var e = new Exception ( "boom" ) ;
112
106
var probe1 = new TestObserver < int > ( this ) ;
113
107
var probe2 = new TestObserver < int > ( this ) ;
@@ -117,17 +111,16 @@ public void An_ObservableSink_must_propagate_error_to_all_observers()
117
111
var d1 = observable . Subscribe ( probe1 ) ;
118
112
var d2 = observable . Subscribe ( probe2 ) ;
119
113
120
- probe1 . ExpectError ( e ) ;
121
- probe1 . ExpectNoMsg ( ) ;
122
-
123
- probe2 . ExpectError ( e ) ;
124
- probe2 . ExpectNoMsg ( ) ;
114
+ await probe1 . ExpectErrorAsync ( e ) ;
115
+ await probe1 . ExpectNoMsgAsync ( ) ;
125
116
117
+ await probe2 . ExpectErrorAsync ( e ) ;
118
+ await probe2 . ExpectNoMsgAsync ( ) ;
126
119
} , Materializer ) ;
127
120
}
128
121
129
122
[ Fact ]
130
- public void An_ObservableSink_subscriber_must_be_disposable ( )
123
+ public async Task An_ObservableSink_subscriber_must_be_disposable ( )
131
124
{
132
125
var probe = new TestObserver < int > ( this ) ;
133
126
var tuple = Source . Queue < int > ( 1 , OverflowStrategy . DropHead )
@@ -142,21 +135,21 @@ public void An_ObservableSink_subscriber_must_be_disposable()
142
135
t . Wait ( TimeSpan . FromSeconds ( 1 ) ) . ShouldBeTrue ( ) ;
143
136
t . Result . ShouldBe ( QueueOfferResult . Enqueued . Instance ) ;
144
137
145
- probe . ExpectEvent ( 1 ) ;
138
+ await probe . ExpectEventAsync ( 1 ) ;
146
139
147
140
t = queue . OfferAsync ( 2 ) ;
148
141
t . Wait ( TimeSpan . FromSeconds ( 1 ) ) . ShouldBeTrue ( ) ;
149
142
t . Result . ShouldBe ( QueueOfferResult . Enqueued . Instance ) ;
150
143
151
- probe . ExpectEvent ( 2 ) ;
144
+ await probe . ExpectEventAsync ( 2 ) ;
152
145
153
146
d1 . Dispose ( ) ;
154
147
155
148
t = queue . OfferAsync ( 3 ) ;
156
149
t . Wait ( TimeSpan . FromSeconds ( 1 ) ) . ShouldBeTrue ( ) ;
157
150
158
- probe . ExpectCompleted ( ) ;
159
- probe . ExpectNoMsg ( ) ;
151
+ await probe . ExpectCompletedAsync ( ) ;
152
+ await probe . ExpectNoMsgAsync ( ) ;
160
153
}
161
154
}
162
155
}
0 commit comments