Failes sometimes on GitHub Actions #1391
-
I am getting intermittent failures when running my integration-tests using a MsSql test container in github actions. I don't have these issues when I run on my own computer, and sometimes they work on github as well. I don't know how I would go about debugging this. The issues are either
or
On my own computer I have to limit xUnit's max threads, if not I get issues with docker (and my computer stalls). I tried setting the maxThreads to 1 for GitHub actions hoping that would help, but it doesn't seem to. The fixtures are set up as follows: public class DatabaseFixture : IAsyncLifetime
{
private readonly MsSqlContainer _msSqlContainer = new MsSqlBuilder().Build();
public async Task InitializeAsync() { await _msSqlContainer.StartAsync(); }
public async Task DisposeAsync() { await _msSqlContainer.DisposeAsync(); }
public string GetConnectionString() => _msSqlContainer.GetConnectionString();
} Which is passed to a larger test fixture /// <summary>
/// Test fixture for integration tests that has an empty MsSql database besides a couple of users.
/// </summary>
public class IntegrationTestFixture : IAsyncLifetime
{
private readonly DatabaseFixture _databaseFixture;
protected readonly CustomWebApplicationFactory AppFactory;
public readonly List<User> Users = TestUsers.GetUsers().ToList();
public IntegrationTestFixture()
{
_databaseFixture = new();
AppFactory = new(_databaseFixture);
}
public virtual async Task InitializeAsync()
{
await _databaseFixture.InitializeAsync();
await using var scope = AppFactory.Services.CreateAsyncScope();
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
await dbContext.Database.EnsureCreatedAsync();
if (await dbContext.Users.AnyAsync(x => x.Id == Users[0].Id))
return;
await dbContext.Users.AddRangeAsync(Users);
await dbContext.SaveChangesAsync();
}
public virtual async Task DisposeAsync()
{
await _databaseFixture.DisposeAsync();
await AppFactory.DisposeAsync();
}
} Which is then passed to unit tests through an |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This configuration looks a bit unusual. How do you configure and set up your database context? I recommend a setup similar to our example:
|
Beta Was this translation helpful? Give feedback.
This configuration looks a bit unusual. How do you configure and set up your database context? I recommend a setup similar to our example: