|
7 | 7 |
|
8 | 8 | using System;
|
9 | 9 | using System.Threading;
|
| 10 | +using System.Threading.Tasks; |
10 | 11 | using Akka.Streams.Dsl;
|
11 | 12 | using Akka.Streams.Implementation;
|
12 | 13 | using Akka.Streams.TestKit;
|
@@ -40,119 +41,130 @@ public SubstreamSubscriptionTimeoutSpec(ITestOutputHelper helper) : base(Config,
|
40 | 41 | }
|
41 | 42 |
|
42 | 43 | [LocalFact(SkipLocal = "Racy on Azure DevOps")]
|
43 |
| - public void GroupBy_and_SplitWhen_must_timeout_and_cancel_substream_publisher_when_no_one_subscribes_to_them_after_some_time() |
| 44 | + public async Task GroupBy_and_SplitWhen_must_timeout_and_cancel_substream_publisher_when_no_one_subscribes_to_them_after_some_time() |
44 | 45 | {
|
45 |
| - this.AssertAllStagesStopped(() => |
46 |
| - { |
| 46 | + await this.AssertAllStagesStoppedAsync(async () => { |
47 | 47 | var subscriber = this.CreateManualSubscriberProbe<(int, Source<int, NotUsed>)>();
|
48 | 48 | var publisherProbe = this.CreatePublisherProbe<int>();
|
49 | 49 | Source.FromPublisher(publisherProbe)
|
50 |
| - .GroupBy(3, x => x%3) |
51 |
| - .Lift(x => x%3) |
| 50 | + .GroupBy(3, x => x % 3) |
| 51 | + .Lift(x => x % 3) |
52 | 52 | .RunWith(Sink.FromSubscriber(subscriber), Materializer);
|
53 | 53 |
|
54 |
| - var downstreamSubscription = subscriber.ExpectSubscription(); |
| 54 | + var downstreamSubscription = await subscriber.ExpectSubscriptionAsync(); |
55 | 55 | downstreamSubscription.Request(100);
|
56 | 56 |
|
57 |
| - publisherProbe.SendNext(1); |
58 |
| - publisherProbe.SendNext(2); |
59 |
| - publisherProbe.SendNext(3); |
60 |
| - |
| 57 | + await publisherProbe.SendNextAsync(1); |
| 58 | + await publisherProbe.SendNextAsync(2); |
| 59 | + await publisherProbe.SendNextAsync(3); |
| 60 | + |
61 | 61 | /*
|
62 | 62 | * Why this spec is skipped: in the event that subscriber.ExpectSubscription() or (subscriber.ExpectNext()
|
63 | 63 | * + s1SubscriberProbe.ExpectSubscription()) exceeds 300ms, the next call to subscriber.ExpectNext will
|
64 | 64 | * fail. This test is too tightly fitted to the timeout duration to be reliable, although somewhat ironically
|
65 | 65 | * it does validate that the underlying cancellation does work!
|
66 | 66 | */
|
67 | 67 |
|
68 |
| - var s1 = subscriber.ExpectNext().Item2; |
| 68 | + var item = await subscriber.ExpectNextAsync(); |
| 69 | + var s1 = item.Item2; |
69 | 70 | // should not break normal usage
|
70 | 71 | var s1SubscriberProbe = this.CreateManualSubscriberProbe<int>();
|
71 | 72 | s1.RunWith(Sink.FromSubscriber(s1SubscriberProbe), Materializer);
|
72 |
| - var s1Subscription = s1SubscriberProbe.ExpectSubscription(); |
| 73 | + var s1Subscription = await s1SubscriberProbe.ExpectSubscriptionAsync(); |
73 | 74 | s1Subscription.Request(100);
|
74 |
| - s1SubscriberProbe.ExpectNext().Should().Be(1); |
| 75 | + var next = await s1SubscriberProbe.ExpectNextAsync(); |
| 76 | + next.Should().Be(1); |
75 | 77 |
|
76 |
| - var s2 = subscriber.ExpectNext().Item2; |
| 78 | + item = await subscriber.ExpectNextAsync(); |
| 79 | + var s2 = item.Item2; |
77 | 80 | // should not break normal usage
|
78 | 81 | var s2SubscriberProbe = this.CreateManualSubscriberProbe<int>();
|
79 | 82 | s2.RunWith(Sink.FromSubscriber(s2SubscriberProbe), Materializer);
|
80 |
| - var s2Subscription = s2SubscriberProbe.ExpectSubscription(); |
| 83 | + var s2Subscription = await s2SubscriberProbe.ExpectSubscriptionAsync(); |
81 | 84 | s2Subscription.Request(100);
|
82 |
| - s2SubscriberProbe.ExpectNext().Should().Be(2); |
| 85 | + next = await s2SubscriberProbe.ExpectNextAsync(); |
| 86 | + next.Should().Be(2); |
83 | 87 |
|
84 |
| - var s3 = subscriber.ExpectNext().Item2; |
| 88 | + item = await subscriber.ExpectNextAsync(); |
| 89 | + var s3 = item.Item2; |
85 | 90 |
|
86 | 91 | // sleep long enough for it to be cleaned up
|
87 |
| - Thread.Sleep(1500); |
| 92 | + await Task.Delay(1500); |
88 | 93 |
|
89 | 94 | // Must be a Sink.seq, otherwise there is a race due to the concat in the `lift` implementation
|
90 | 95 | Action action = () => s3.RunWith(Sink.Seq<int>(), Materializer).Wait(RemainingOrDefault);
|
91 | 96 | action.Should().Throw<SubscriptionTimeoutException>();
|
92 | 97 |
|
93 |
| - publisherProbe.SendComplete(); |
| 98 | + await publisherProbe.SendCompleteAsync(); |
94 | 99 | }, Materializer);
|
95 | 100 | }
|
96 | 101 |
|
97 | 102 | [Fact]
|
98 |
| - public void GroupBy_and_SplitWhen_must_timeout_and_stop_groupBy_parent_actor_if_none_of_the_substreams_are_actually_consumed() |
| 103 | + public async Task GroupBy_and_SplitWhen_must_timeout_and_stop_groupBy_parent_actor_if_none_of_the_substreams_are_actually_consumed() |
99 | 104 | {
|
100 |
| - this.AssertAllStagesStopped(() => |
101 |
| - { |
| 105 | + await this.AssertAllStagesStoppedAsync(async() => { |
102 | 106 | var subscriber = this.CreateManualSubscriberProbe<(int, Source<int, NotUsed>)>();
|
103 | 107 | var publisherProbe = this.CreatePublisherProbe<int>();
|
104 | 108 | Source.FromPublisher(publisherProbe)
|
105 | 109 | .GroupBy(2, x => x % 2)
|
106 | 110 | .Lift(x => x % 2).RunWith(Sink.FromSubscriber(subscriber), Materializer);
|
107 | 111 |
|
108 | 112 |
|
109 |
| - var downstreamSubscription = subscriber.ExpectSubscription(); |
| 113 | + var downstreamSubscription = await subscriber.ExpectSubscriptionAsync(); |
110 | 114 | downstreamSubscription.Request(100);
|
111 | 115 |
|
112 |
| - publisherProbe.SendNext(1); |
113 |
| - publisherProbe.SendNext(2); |
114 |
| - publisherProbe.SendNext(3); |
115 |
| - publisherProbe.SendComplete(); |
| 116 | + await publisherProbe.SendNextAsync(1); |
| 117 | + await publisherProbe.SendNextAsync(2); |
| 118 | + await publisherProbe.SendNextAsync(3); |
| 119 | + await publisherProbe.SendCompleteAsync(); |
116 | 120 |
|
117 |
| - subscriber.ExpectNext(); |
118 |
| - subscriber.ExpectNext(); |
| 121 | + await subscriber.ExpectNextAsync(); |
| 122 | + await subscriber.ExpectNextAsync(); |
119 | 123 | }, Materializer);
|
120 | 124 | }
|
121 | 125 |
|
122 | 126 | [LocalFact(SkipLocal = "Racy on Azure DevOps")]
|
123 |
| - public void GroupBy_and_SplitWhen_must_not_timeout_and_cancel_substream_publisher_when_they_have_been_subscribed_to() |
| 127 | + public async Task GroupBy_and_SplitWhen_must_not_timeout_and_cancel_substream_publisher_when_they_have_been_subscribed_to() |
124 | 128 | {
|
125 | 129 | var subscriber = this.CreateManualSubscriberProbe<(int, Source<int, NotUsed>)>();
|
126 | 130 | var publisherProbe = this.CreatePublisherProbe<int>();
|
127 | 131 | Source.FromPublisher(publisherProbe)
|
128 | 132 | .GroupBy(2, x => x % 2)
|
129 | 133 | .Lift(x => x % 2).RunWith(Sink.FromSubscriber(subscriber), Materializer);
|
130 | 134 |
|
131 |
| - var downstreamSubscription = subscriber.ExpectSubscription(); |
| 135 | + var downstreamSubscription = await subscriber.ExpectSubscriptionAsync(); |
132 | 136 | downstreamSubscription.Request(10);
|
133 | 137 |
|
134 |
| - publisherProbe.SendNext(1); |
135 |
| - publisherProbe.SendNext(2); |
| 138 | + await publisherProbe.SendNextAsync(1); |
| 139 | + await publisherProbe.SendNextAsync(2); |
136 | 140 |
|
137 |
| - var s1 = subscriber.ExpectNext().Item2; |
| 141 | + var item = await subscriber.ExpectNextAsync(); |
| 142 | + var s1 = item.Item2; |
138 | 143 | var s1SubscriberProbe = this.CreateManualSubscriberProbe<int>();
|
139 | 144 | s1.RunWith(Sink.FromSubscriber(s1SubscriberProbe), Materializer);
|
140 |
| - var s1Subscription = s1SubscriberProbe.ExpectSubscription(); |
| 145 | + var s1Subscription = await s1SubscriberProbe.ExpectSubscriptionAsync(); |
141 | 146 | s1Subscription.Request(1);
|
142 |
| - s1SubscriberProbe.ExpectNext().Should().Be(1); |
| 147 | + var s1Subscriber = await s1SubscriberProbe.ExpectNextAsync(); |
| 148 | + s1Subscriber.Should().Be(1); |
143 | 149 |
|
144 |
| - var s2 = subscriber.ExpectNext().Item2; |
| 150 | + item = await subscriber.ExpectNextAsync(); |
| 151 | + var s2 = item.Item2; |
145 | 152 | var s2SubscriberProbe = this.CreateManualSubscriberProbe<int>();
|
146 | 153 | s2.RunWith(Sink.FromSubscriber(s2SubscriberProbe), Materializer);
|
147 |
| - var s2Subscription = s2SubscriberProbe.ExpectSubscription(); |
148 |
| - Thread.Sleep(1500); |
| 154 | + var s2Subscription = await s2SubscriberProbe.ExpectSubscriptionAsync(); |
| 155 | + await Task.Delay(1500); |
149 | 156 | s2Subscription.Request(100);
|
150 |
| - s2SubscriberProbe.ExpectNext().Should().Be(2); |
| 157 | + |
| 158 | + var s2Subscriber = await s2SubscriberProbe.ExpectNextAsync(); |
| 159 | + s2Subscriber.Should().Be(2); |
| 160 | + |
151 | 161 | s1Subscription.Request(100);
|
152 |
| - publisherProbe.SendNext(3); |
153 |
| - publisherProbe.SendNext(4); |
154 |
| - s1SubscriberProbe.ExpectNext().Should().Be(3); |
155 |
| - s2SubscriberProbe.ExpectNext().Should().Be(4); |
| 162 | + await publisherProbe.SendNextAsync(3); |
| 163 | + await publisherProbe.SendNextAsync(4); |
| 164 | + var s1S = await s1SubscriberProbe.ExpectNextAsync(); |
| 165 | + s1S.Should().Be(3); |
| 166 | + var s2S = await s2SubscriberProbe.ExpectNextAsync(); |
| 167 | + s2S.Should().Be(4); |
156 | 168 | }
|
157 | 169 | }
|
158 | 170 | }
|
0 commit comments