Skip to content

Commit ca3ac62

Browse files
authored
fix Asynclocal dipose and async db deletion (#423)
1 parent 84add62 commit ca3ac62

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

PrismaDotnetApi/PrismaApi.Test/Configuration/TestClientScope.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ namespace PrismaApi.Test.Configuration;
55

66
public class TestClientScope : IDisposable
77
{
8-
private static readonly AsyncLocal<List<KeyValuePair<string, string>>> CurrentHeaders = new();
9-
private static readonly AsyncLocal<TestPersonProfile> CurrentUser = new();
8+
private static readonly AsyncLocal<List<KeyValuePair<string, string>>?> CurrentHeaders = new();
9+
private static readonly AsyncLocal<TestPersonProfile?> CurrentUser = new();
1010
private static readonly AsyncLocal<Guid?> CurrentAppId = new();
1111

1212
public TestClientScope(Guid id) => CurrentAppId.Value = id;
1313

1414
public TestClientScope(TestPersonProfile profile) => CurrentUser.Value = profile;
1515

16-
public void Dispose() => GC.SuppressFinalize(this);
16+
public void Dispose()
17+
{
18+
CurrentHeaders.Value = null;
19+
CurrentUser.Value = null;
20+
CurrentAppId.Value = null;
21+
22+
GC.SuppressFinalize(this);
23+
}
1724

1825
public TestClientScope SetSigninAppId(Guid? appId)
1926
{

PrismaDotnetApi/PrismaApi.Test/Fixture/PrismaApiFixture.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ public async Task DisposeAsync()
4646
{
4747
using var scope = ApiFactory.Services.CreateScope();
4848
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
49-
db.Database.EnsureDeleted();
50-
49+
await db.Database.EnsureDeletedAsync();
5150
GC.SuppressFinalize(db);
52-
await Task.CompletedTask;
5351
}
5452

5553
public TestClientScope UserScope() => new(PrismaUser);

0 commit comments

Comments
 (0)