Skip to content

Commit e55a5a5

Browse files
authored
[CS1998] This async method lacks 'await' operators and will run synchronously (#6513)
* This async method lacks 'await' operators and will run synchronously * removed `async`/`await` * [improves] - `AsyncEnumerable.cs` - `TestPublisher.cs` - `Utils.cs` - `EventFilterApplier.cs` - `BlockingQueue.cs` - `TestKitBase_AwaitConditions.cs` - `TestKitBase_Within.cs` * Fix `CS1998` * changed it `Task.FromResult` to `Task.Run`
1 parent 76baf9d commit e55a5a5

File tree

50 files changed

+251
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+251
-244
lines changed

src/contrib/cluster/Akka.Cluster.Metrics.Tests.MultiNode/ClusterMetricsExtensionSpec.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ await AwaitAssertAsync(() =>
109109
MetricsView.ClusterMetrics.Count.Should().Be(Roles.Count);
110110
}, TimeSpan.FromSeconds(30));
111111

112-
await WithinAsync(10.Seconds(), async () =>
113-
{
112+
await WithinAsync(10.Seconds(), () => {
114113
var collector = new MetricsCollectorBuilder().Build(Cluster.System);
115114
collector.Sample().Metrics.Count.Should().BeGreaterThan(3);
116115
EnterBarrier("after");
116+
return Task.CompletedTask;
117117
});
118118
}
119119

src/contrib/cluster/Akka.Cluster.Metrics.Tests.MultiNode/ClustetMetricsRoutingSpec.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ private async Task Should_prefer_node_with_more_free_memory_capacity()
246246

247247
await RunOnAsync(async () =>
248248
{
249-
await WithinAsync(20.Seconds(), async () =>
250-
{
251-
Sys.ActorOf(Props.Create<AdaptiveLoadBalancingRouterConfig.MemoryAllocator>(), "memory-allocator")
252-
.Tell(AdaptiveLoadBalancingRouterConfig.AllocateMemory.Instance);
253-
ExpectMsg("done");
249+
await WithinAsync(20.Seconds(), () => {
250+
Sys.ActorOf(Props.Create<AdaptiveLoadBalancingRouterConfig.MemoryAllocator>(), "memory-allocator")
251+
.Tell(AdaptiveLoadBalancingRouterConfig.AllocateMemory.Instance);
252+
ExpectMsg("done");
253+
return Task.CompletedTask;
254254
});
255255
}, _config.Node2);
256256

src/contrib/cluster/Akka.Cluster.Metrics.Tests.MultiNode/Sample/StatsSampleSpec.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,27 @@ public async Task Stats_sample_should_illustrate_how_to_startup_cluster()
8888

8989
private async Task Should_startup_cluster()
9090
{
91-
await WithinAsync(15.Seconds(), async () =>
92-
{
91+
await WithinAsync(15.Seconds(), () => {
9392
var cluster = Cluster.Get(Sys);
9493
cluster.Subscribe(TestActor, typeof(ClusterEvent.MemberUp));
9594
ExpectMsg<ClusterEvent.CurrentClusterState>();
9695

9796
var firstAddress = Node(_config.First).Address;
9897
var secondAddress = Node(_config.Second).Address;
9998
var thirdAddress = Node(_config.Third).Address;
100-
99+
101100
cluster.Join(firstAddress);
102101

103102
Sys.ActorOf(Props.Create<StatsWorker>(), "statsWorker");
104103
Sys.ActorOf(Props.Create<StatsService>(), "statsService");
105104

106105
ReceiveN(3).Select(m => (m as ClusterEvent.MemberUp).Member.Address).Distinct()
107106
.Should().BeEquivalentTo(firstAddress, secondAddress, thirdAddress);
108-
107+
109108
cluster.Unsubscribe(TestActor);
110-
109+
111110
EnterBarrier("all-up");
111+
return Task.CompletedTask;
112112
});
113113
}
114114

src/contrib/cluster/Akka.Cluster.Tools.Tests/PublishSubscribe/DistributedPubSubMediatorSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public async Task DistributedPubSubMediator_should_send_messages_to_dead_letter(
8080

8181
// assert
8282
await EventFilter.DeadLetter<object>().ExpectAsync(1,
83-
async () => { mediator.Tell(new Publish("pub-sub", "hit")); });
83+
() => { mediator.Tell(new Publish("pub-sub", "hit")); return Task.CompletedTask; });
8484
}
8585
}
8686

src/contrib/cluster/Akka.Cluster.Tools.Tests/Singleton/ClusterSingletonProxySpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public async Task ClusterSingletonProxy_with_zero_buffering_should_work()
5353

5454
// have to wait for cluster singleton to be ready, otherwise message will be rejected
5555
await AwaitConditionAsync(
56-
async () => Cluster.Get(testSystem.Sys).State.Members.Count(m => m.Status == MemberStatus.Up) == 2,
56+
() => Task.FromResult(Cluster.Get(testSystem.Sys).State.Members.Count(m => m.Status == MemberStatus.Up) == 2),
5757
TimeSpan.FromSeconds(30));
5858

5959
try

src/contrib/cluster/Akka.DistributedData.Tests/ReplicatorSpecs.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public async Task Bugfix_Duplicate_Publish()
173173
await ReplicatorDuplicatePublish();
174174
}
175175

176-
private async Task ReplicatorDuplicatePublish()
176+
private Task ReplicatorDuplicatePublish()
177177
{
178178
var p1 = CreateTestProbe(_sys1);
179179
var p2 = CreateTestProbe(_sys2);
@@ -205,6 +205,7 @@ private async Task ReplicatorDuplicatePublish()
205205

206206
// no probe should receive an update
207207
p2.ExpectNoMsg(TimeSpan.FromSeconds(1));
208+
return Task.CompletedTask;
208209
}
209210

210211
/// <summary>
@@ -217,7 +218,7 @@ public async Task Bugfix_4198_PNCounterDictionary_Merge()
217218
await PNCounterDictionary_Should_Merge();
218219
}
219220

220-
private async Task PNCounterDictionary_Should_Merge()
221+
private Task PNCounterDictionary_Should_Merge()
221222
{
222223
var p1 = CreateTestProbe(_sys1);
223224
var p2 = CreateTestProbe(_sys2);
@@ -262,6 +263,7 @@ private async Task PNCounterDictionary_Should_Merge()
262263
});
263264

264265
Sys.Log.Info("Done");
266+
return Task.CompletedTask;
265267
}
266268

267269
/// <summary>
@@ -366,7 +368,7 @@ public async Task Bugfix_4302_ORMultiValueDictionary_Merge()
366368
await ORMultiValueDictionary_Should_Merge();
367369
}
368370

369-
private async Task ORMultiValueDictionary_Should_Merge()
371+
private Task ORMultiValueDictionary_Should_Merge()
370372
{
371373
var changedProbe = CreateTestProbe(_sys2);
372374

@@ -475,6 +477,7 @@ private async Task ORMultiValueDictionary_Should_Merge()
475477
changedProbe.ExpectMsg<Changed>(g => Equals(g.Key, _keyJ)).Get(_keyJ).Entries);
476478
});
477479
});
480+
return Task.CompletedTask;
478481
}
479482

480483
private void VerifyMultiValueDictionaryEntries(

src/core/Akka.Cluster.Tests/ClusterLogSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected async Task AwaitUpAsync()
5252
{
5353
await WithinAsync(TimeSpan.FromSeconds(10), async() =>
5454
{
55-
await AwaitConditionAsync(async () => ClusterView.IsSingletonCluster);
55+
await AwaitConditionAsync(() => Task.FromResult(ClusterView.IsSingletonCluster));
5656
ClusterView.Self.Address.ShouldBe(_selfAddress);
5757
ClusterView.Members.Select(m => m.Address).ShouldBe(new Address[] { _selfAddress });
5858
await AwaitAssertAsync(() => ClusterView.Status.ShouldBe(MemberStatus.Up));

src/core/Akka.Cluster.Tests/ClusterSpec.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public async Task A_cluster_must_initially_become_singleton_cluster_when_joining
8080
ClusterView.Members.Count.Should().Be(0);
8181
_cluster.Join(_selfAddress);
8282
LeaderActions(); // Joining -> Up
83-
await AwaitConditionAsync(async () => ClusterView.IsSingletonCluster);
83+
await AwaitConditionAsync(() => Task.FromResult(ClusterView.IsSingletonCluster));
8484
ClusterView.Self.Address.Should().Be(_selfAddress);
8585
ClusterView.Members.Select(m => m.Address).ToImmutableHashSet()
8686
.Should().BeEquivalentTo(ImmutableHashSet.Create(_selfAddress));
@@ -259,7 +259,7 @@ public async Task A_cluster_must_cancel_LeaveAsync_task_if_CancellationToken_fir
259259

260260
// Cancelling the first task
261261
cts.Cancel();
262-
await AwaitConditionAsync(async () => task1.IsCanceled, null, "Task should be cancelled");
262+
await AwaitConditionAsync(() => Task.FromResult(task1.IsCanceled), null, "Task should be cancelled");
263263

264264
await WithinAsync(TimeSpan.FromSeconds(10), async () =>
265265
{
@@ -274,12 +274,12 @@ await WithinAsync(TimeSpan.FromSeconds(10), async () =>
274274
ExpectMsg<ClusterEvent.MemberRemoved>().Member.Address.Should().Be(_selfAddress);
275275

276276
// Second task should complete (not cancelled)
277-
await AwaitConditionAsync(async () => task2.IsCompleted && !task2.IsCanceled, null, "Task should be completed, but not cancelled.");
277+
await AwaitConditionAsync(() => Task.FromResult(task2.IsCompleted && !task2.IsCanceled), null, "Task should be completed, but not cancelled.");
278278
}, cancellationToken: cts.Token);
279279

280280
// Subsequent LeaveAsync() tasks expected to complete immediately (not cancelled)
281281
var task3 = _cluster.LeaveAsync();
282-
await AwaitConditionAsync(async () => task3.IsCompleted && !task3.IsCanceled, null, "Task should be completed, but not cancelled.");
282+
await AwaitConditionAsync(() => Task.FromResult(task3.IsCompleted && !task3.IsCanceled), null, "Task should be completed, but not cancelled.");
283283
}
284284

285285
[Fact]

src/core/Akka.Docs.Tests/Actors/ReceiveTimeoutSpecs.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected override void PreStart()
4747
// </ReceiveTimeoutActor>
4848

4949
[Fact]
50-
public async Task ShouldReceiveTimeoutActors()
50+
public Task ShouldReceiveTimeoutActors()
5151
{
5252
var receiveTimeout = Sys.ActorOf(
5353
Props.Create(() => new ReceiveTimeoutActor(TimeSpan.FromMilliseconds(100), TestActor)),
@@ -58,6 +58,7 @@ public async Task ShouldReceiveTimeoutActors()
5858

5959
// then should receive timeout due to inactivity
6060
ExpectMsg("timeout", TimeSpan.FromSeconds(30));
61+
return Task.CompletedTask;
6162
}
6263
}
6364
}

src/core/Akka.Persistence.Tests/ReceivePersistentActorAsyncAwaitSpec.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,9 @@ public AsyncFailingActor(string persistenceId)
533533

534534
RecoverAny(o => { });
535535

536-
CommandAsync<string>(async m =>
537-
{
536+
CommandAsync<string>(m => {
538537
ThrowException();
538+
return Task.CompletedTask;
539539
});
540540
}
541541

@@ -599,8 +599,7 @@ public AsyncReentrantActor(string persistenceId)
599599

600600
RecoverAny(o => { });
601601

602-
CommandAsync<string>(async msg =>
603-
{
602+
CommandAsync<string>(msg => {
604603
var sender = Sender;
605604
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
606605
Task.Run(() =>
@@ -612,6 +611,7 @@ public AsyncReentrantActor(string persistenceId)
612611
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
613612

614613
Thread.Sleep(3000);
614+
return Task.CompletedTask;
615615
});
616616
}
617617
}
@@ -635,7 +635,7 @@ public void Actor_PipeTo_should_not_be_delayed_by_async_receive()
635635
}
636636

637637
[Fact]
638-
public async Task Actor_receiveasync_overloads_should_work()
638+
public Task Actor_receiveasync_overloads_should_work()
639639
{
640640
var actor = Sys.ActorOf(Props.Create(() => new AsyncAwaitActor("pid")));
641641

@@ -647,8 +647,7 @@ public async Task Actor_receiveasync_overloads_should_work()
647647

648648
actor.Tell(1.0);
649649
ExpectMsg<string>(m => "handled".Equals(m), TimeSpan.FromMilliseconds(1000));
650-
651-
650+
return Task.CompletedTask;
652651
}
653652
}
654653
}

src/core/Akka.Persistence/Journal/MemoryJournal.cs

+7-9
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,20 @@ protected override bool ReceivePluginInternal(object message)
182182
}
183183
}
184184

185-
private async Task<(IEnumerable<string> Ids, int LastOrdering)> SelectAllPersistenceIdsAsync(int offset)
185+
private Task<(IEnumerable<string> Ids, int LastOrdering)> SelectAllPersistenceIdsAsync(int offset)
186186
{
187-
return (new HashSet<string>(_allMessages.Skip(offset).Select(p => p.PersistenceId)), _allMessages.Count);
187+
return Task.FromResult<(IEnumerable<string> Ids, int LastOrdering)>((new HashSet<string>(_allMessages.Skip(offset).Select(p => p.PersistenceId)), _allMessages.Count));
188188
}
189189

190190
/// <summary>
191191
/// Replays all events with given tag withing provided boundaries from memory.
192192
/// </summary>
193193
/// <param name="replay">TBD</param>
194194
/// <returns>TBD</returns>
195-
private async Task<int> ReplayTaggedMessagesAsync(ReplayTaggedMessages replay)
195+
private Task<int> ReplayTaggedMessagesAsync(ReplayTaggedMessages replay)
196196
{
197197
if (!_tagsToMessagesMapping.ContainsKey(replay.Tag))
198-
return 0;
198+
return Task.FromResult(0);
199199

200200
int index = 0;
201201
foreach (var persistence in _tagsToMessagesMapping[replay.Tag]
@@ -207,10 +207,10 @@ private async Task<int> ReplayTaggedMessagesAsync(ReplayTaggedMessages replay)
207207
index++;
208208
}
209209

210-
return _tagsToMessagesMapping[replay.Tag].Count - 1;
210+
return Task.FromResult(_tagsToMessagesMapping[replay.Tag].Count - 1);
211211
}
212212

213-
private async Task<int> ReplayAllEventsAsync(ReplayAllEvents replay)
213+
private Task<int> ReplayAllEventsAsync(ReplayAllEvents replay)
214214
{
215215
int index = 0;
216216
var replayed = _allMessages
@@ -222,8 +222,7 @@ private async Task<int> ReplayAllEventsAsync(ReplayAllEvents replay)
222222
replay.ReplyTo.Tell(new ReplayedEvent(message, replay.FromOffset + index), ActorRefs.NoSender);
223223
index++;
224224
}
225-
226-
return _allMessages.Count - 1;
225+
return Task.FromResult(_allMessages.Count - 1);
227226
}
228227

229228
#region QueryAPI
@@ -439,7 +438,6 @@ public sealed class ReplayedEvent : INoSerializationVerificationNeeded, IDeadLet
439438
/// TBD
440439
/// </summary>
441440
/// <param name="persistent">TBD</param>
442-
/// <param name="tag">TBD</param>
443441
/// <param name="offset">TBD</param>
444442
public ReplayedEvent(IPersistentRepresentation persistent, int offset)
445443
{

src/core/Akka.Remote.Tests/ActorsLeakSpec.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ await EventFilter.Warning(contains: "Association with remote system").ExpectOneA
234234
* Wait for the ReliableDeliverySupervisor to receive its "TooLongIdle" message,
235235
* which will throw a HopelessAssociation wrapped around a TimeoutException.
236236
*/
237-
await EventFilter.Exception<TimeoutException>().ExpectOneAsync(async () => { });
237+
await EventFilter.Exception<TimeoutException>().ExpectOneAsync(() => { return Task.CompletedTask; });
238238

239239
await AwaitAssertAsync(() =>
240240
{

src/core/Akka.Remote.Tests/RemotingSpec.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ public async Task Stash_inbound_connections_until_UID_is_known_for_pending_outbo
505505
(new ActorAssociationEventListener(remoteTransportProbe)));
506506

507507
// Hijack associations through the test transport
508-
await AwaitConditionAsync(async () => registry.TransportsReady(rawLocalAddress, rawRemoteAddress));
508+
await AwaitConditionAsync(() => Task.FromResult(registry.TransportsReady(rawLocalAddress, rawRemoteAddress)));
509509
var testTransport = registry.TransportFor(rawLocalAddress).Value.Item1;
510510
testTransport.WriteBehavior.PushConstant(true);
511511

@@ -588,7 +588,7 @@ public async Task Properly_quarantine_stashed_inbound_connections()
588588
(new ActorAssociationEventListener(remoteTransportProbe)));
589589

590590
// Hijack associations through the test transport
591-
await AwaitConditionAsync(async () => registry.TransportsReady(rawLocalAddress, rawRemoteAddress));
591+
await AwaitConditionAsync(() => Task.FromResult(registry.TransportsReady(rawLocalAddress, rawRemoteAddress)));
592592
var testTransport = registry.TransportFor(rawLocalAddress).Value.Item1;
593593
testTransport.WriteBehavior.PushConstant(true);
594594

0 commit comments

Comments
 (0)