Skip to content

Commit 61ea495

Browse files
committed
Use async [Benchmark] methods
BenchmarkDotNet has supported async benchmark methods for a long time — the old comment claiming otherwise was wrong, and the .Result blocking call was unnecessary. IterationSetup stays sync (async support there needs BDN 0.16+).
1 parent a28d3a7 commit 61ea495

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

backend/FwLite/FwLiteProjectSync.Tests/SyncBenchmark.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace FwLiteProjectSync.Tests;
2121
public class SyncBenchmark(Sena3Fixture fixture, ITestOutputHelper output)
2222
{
2323
[Fact]
24-
public void First_Sync_Sena3()
24+
public async Task First_Sync_Sena3()
2525
{
2626
FirstSyncBench.Fixture = fixture;
2727
#if DEBUG
@@ -30,7 +30,7 @@ public void First_Sync_Sena3()
3030
output.WriteLine("Debug build: running once for coverage; threshold enforced in Release only.");
3131
var bench = new FirstSyncBench();
3232
bench.IterationSetup();
33-
try { _ = bench.SyncFromEmpty(); }
33+
try { _ = await bench.SyncFromEmpty(); }
3434
finally { bench.IterationCleanup(); }
3535
#else
3636
using var scope = new AssertionScope();
@@ -47,7 +47,7 @@ public void First_Sync_Sena3()
4747
}
4848
}
4949

50-
// BenchmarkDotNet has no async support. .Result is intentional and will not deadlock.
50+
// IterationSetup must be sync until BenchmarkDotNet 0.16+; until then GetAwaiter().GetResult() is intentional.
5151
#pragma warning disable VSTHRD002
5252

5353
public class FirstSyncBench
@@ -77,9 +77,9 @@ public void IterationSetup()
7777
}
7878

7979
[Benchmark]
80-
public SyncResult SyncFromEmpty()
80+
public async Task<SyncResult> SyncFromEmpty()
8181
{
82-
return _syncService.Sync(_project.CrdtApi, _project.FwDataApi, _projectSnapshot).Result;
82+
return await _syncService.Sync(_project.CrdtApi, _project.FwDataApi, _projectSnapshot);
8383
}
8484

8585
[IterationCleanup]

backend/FwLite/FwLiteProjectSync.Tests/SyncMutationBenchmark.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace FwLiteProjectSync.Tests;
2424
public class SyncMutationBenchmark(Sena3Fixture fixture, ITestOutputHelper output)
2525
{
2626
[Fact]
27-
public void Sync_AfterMutations_Sena3()
27+
public async Task Sync_AfterMutations_Sena3()
2828
{
2929
MutationSyncBench.Fixture = fixture;
3030
#if DEBUG
@@ -36,7 +36,7 @@ public void Sync_AfterMutations_Sena3()
3636
{
3737
bench.Profile = profile;
3838
bench.IterationSetup();
39-
try { _ = bench.SyncAfterMutations(); }
39+
try { _ = await bench.SyncAfterMutations(); }
4040
finally { bench.IterationCleanup(); }
4141
}
4242
#else
@@ -119,9 +119,9 @@ public void IterationSetup()
119119
}
120120

121121
[Benchmark]
122-
public SyncResult SyncAfterMutations()
122+
public async Task<SyncResult> SyncAfterMutations()
123123
{
124-
return _syncService.Sync(_project.CrdtApi, _project.FwDataApi, _projectSnapshot).Result;
124+
return await _syncService.Sync(_project.CrdtApi, _project.FwDataApi, _projectSnapshot);
125125
}
126126

127127
[IterationCleanup]

0 commit comments

Comments
 (0)