Skip to content

Commit aaaecbf

Browse files
author
Nate McMaster
committed
Ensure each test run gets a unique in-memory database
1 parent f4cb17a commit aaaecbf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Middleware/HealthChecks.EntityFrameworkCore/test/DbContextHealthCheckTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ public async Task CheckAsync_CustomTest_Unhealthy()
104104
}
105105
}
106106

107+
private static int _testDbCounter;
108+
107109
private static IServiceProvider CreateServices(
108110
Func<TestDbContext, CancellationToken, Task<bool>> testQuery = null,
109111
HealthStatus failureStatus = HealthStatus.Unhealthy)
110112
{
111113
var serviceCollection = new ServiceCollection();
112-
serviceCollection.AddDbContext<TestDbContext>(o => o.UseInMemoryDatabase("Test"));
114+
serviceCollection.AddDbContext<TestDbContext>(o => o.UseInMemoryDatabase("Test" + Interlocked.Increment(ref _testDbCounter)));
113115

114116
var builder = serviceCollection.AddHealthChecks();
115117
builder.AddDbContextCheck<TestDbContext>("test", failureStatus, new[] { "tag1", "tag2", }, testQuery);

0 commit comments

Comments
 (0)