Skip to content

Commit ad4b7bf

Browse files
fix: * IterationSetup|IterationCleanup does not support async
dotnet/BenchmarkDotNet#2111
1 parent 5739931 commit ad4b7bf

File tree

4 files changed

+19
-35
lines changed

4 files changed

+19
-35
lines changed

Src/NpgsqlBenchmark/Benchmarks/BinaryImportMap.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,17 @@ public async Task GlobalCleanup()
3030
}
3131

3232
[IterationSetup]
33-
public async Task IterationSetup()
33+
public void IterationSetup()
3434
{
35-
_connection = await _npgsqlDataSource.OpenConnectionAsync();
35+
_connection = _npgsqlDataSource.OpenConnection();
3636
}
3737

3838
[IterationCleanup]
39-
public async Task IterationCleanup()
39+
public void IterationCleanup()
4040
{
4141
try
4242
{
43-
var connection = _connection;
44-
if (connection != null)
45-
{
46-
await connection.DisposeAsync();
47-
}
43+
_connection?.Dispose();
4844
}
4945
catch
5046
{

Src/NpgsqlBenchmark/Benchmarks/CompareDapper.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,17 @@ public async Task GlobalCleanup()
3333
}
3434

3535
[IterationSetup]
36-
public async Task IterationSetup()
36+
public void IterationSetup()
3737
{
38-
_connection = await _npgsqlDataSource.OpenConnectionAsync();
38+
_connection = _npgsqlDataSource.OpenConnection();
3939
}
4040

4141
[IterationCleanup]
42-
public async Task IterationCleanup()
42+
public void IterationCleanup()
4343
{
4444
try
4545
{
46-
var connection = _connection;
47-
if (connection != null)
48-
{
49-
await connection.DisposeAsync();
50-
}
46+
_connection?.Dispose();
5147
}
5248
catch
5349
{
@@ -113,7 +109,7 @@ WHERE p.id > @id
113109
new { id = 49999 },
114110
splitOn: "identification_id"
115111
)
116-
.ToList();
112+
.AsList();
117113
}
118114
}
119115

@@ -144,7 +140,7 @@ public async Task DapperAOT()
144140
{
145141
for (int i = 0; i < Size; i++)
146142
{
147-
var persons = DapperAOTGetAllPerson(_connection, 49999).ToList();
143+
var persons = DapperAOTGetAllPerson(_connection, 49999).AsList();
148144
}
149145
}
150146
}

Src/NpgsqlBenchmark/Benchmarks/ComparePrepareDapper.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,17 @@ public async Task GlobalCleanup()
3131
}
3232

3333
[IterationSetup]
34-
public async Task IterationSetup()
34+
public void IterationSetup()
3535
{
36-
_connection = await _npgsqlDataSource.OpenConnectionAsync();
36+
_connection = _npgsqlDataSource.OpenConnection();
3737
}
3838

3939
[IterationCleanup]
40-
public async Task IterationCleanup()
40+
public void IterationCleanup()
4141
{
4242
try
4343
{
44-
var connection = _connection;
45-
if (connection != null)
46-
{
47-
await connection.DisposeAsync();
48-
}
44+
_connection?.Dispose();
4945
}
5046
catch
5147
{
@@ -120,7 +116,7 @@ WHERE p.id < @id
120116
param,
121117
splitOn: "identification_id"
122118
)
123-
.ToList();
119+
.AsList();
124120
}
125121
}
126122
}

Src/NpgsqlBenchmark/Benchmarks/QueryMap.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,17 @@ public async Task GlobalCleanup()
3131
}
3232

3333
[IterationSetup]
34-
public async Task IterationSetup()
34+
public void IterationSetup()
3535
{
36-
_connection = await _npgsqlDataSource.OpenConnectionAsync();
36+
_connection = _npgsqlDataSource.OpenConnection();
3737
}
3838

3939
[IterationCleanup]
40-
public async Task IterationCleanup()
40+
public void IterationCleanup()
4141
{
4242
try
4343
{
44-
var connection = _connection;
45-
if (connection != null)
46-
{
47-
await connection.DisposeAsync();
48-
}
44+
_connection?.Dispose();
4945
}
5046
catch
5147
{

0 commit comments

Comments
 (0)