Skip to content

[Bug]: Version 1.11.45 breaks integration tests with migrations in Github Workflow #4737

@michaltalaga

Description

@michaltalaga

Description

After upgrading to Version 1.11.45 (or any later version) our integration tests no longer work in github workflow.
It works with lower versions and it also works on a dev machine with this or future versions too.
There is no other change in any code, ci setup or other packages. jsut going up to 1.11.45.
Everything works with 1.11.28

Our code checks for and applies migrations on startup

public WebApplication ApplyMigrations()
{
using var scope = app.Services.CreateScope();
foreach (var dbContext in scope.ServiceProvider.GetDbContexts())
{
var pendingMigrations = dbContext.Database.GetPendingMigrations();
if (pendingMigrations.Any())
{
dbContext.Database.SetCommandTimeout(TimeSpan.FromMinutes(30));
dbContext.Database.Migrate();
}
}
var tickerQDbContext = scope.ServiceProvider.GetRequiredService();
tickerQDbContext.Database.Migrate();
return app;
}

extension(IServiceProvider sp)
{
    public IEnumerable<DbContext> GetDbContexts() => registeredDbContextTypes.Select(t => (DbContext)sp.GetRequiredService(t)); // we save DbContextTypes when setting up the services as there is no easy way to get them out later.
} 

in tests we're using
https://tunit.dev/docs/guides/best-practices/#sharing-expensive-resources

and WebApplicationFactory

Expected Behavior

my tests should work as expected or a breaking change should be listed on the release

Actual Behavior

as in description

Steps to Reproduce

it it's not gonna be obvious on your side what can potentially cause this I may setup a simplified solution to repro this

TUnit Version

1.11.45

.NET Version

NET 10

Operating System

Linux

IDE / Test Runner

Other (please specify in additional context)

Error Output / Stack Trace

NpgsqlException: Failed to connect to 127.0.0.1:5435
2026-02-11T03:16:30.7106502Z #15 53.40   from /src/BackendService.Tests/bin/Release/net10.0/BackendService.Tests.dll (net10.0|x64)
2026-02-11T03:16:30.7107626Z #15 53.40   TUnit.Engine.Exceptions.TestFailedException: NpgsqlException: Failed to connect to 127.0.0.1:5435
2026-02-11T03:16:30.7108662Z #15 53.41     at Npgsql.Internal.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
2026-02-11T03:16:30.7109847Z #15 53.41     at Npgsql.Internal.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
2026-02-11T03:16:30.7112008Z #15 53.41     at Npgsql.Internal.NpgsqlConnector.<Open>g__OpenCore|209_0(NpgsqlConnector conn, String username, SslMode sslMode, GssEncryptionMode gssEncMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
2026-02-11T03:16:30.7130162Z #15 53.41     at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
2026-02-11T03:16:30.7131999Z #15 53.41     at Npgsql.PoolingDataSource.OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
2026-02-11T03:16:30.7134218Z #15 53.41     at Npgsql.PoolingDataSource.<Get>g__RentAsync|33_0(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
2026-02-11T03:16:30.7135788Z #15 53.41     at Npgsql.NpgsqlConnection.<Open>g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken)
2026-02-11T03:16:30.7136700Z #15 53.41     at Npgsql.NpgsqlConnection.Open()
2026-02-11T03:16:30.7137693Z #15 53.41     at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
2026-02-11T03:16:30.7139006Z #15 53.41     at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternal(Boolean errorsExpected)
2026-02-11T03:16:30.7140222Z #15 53.41     at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
2026-02-11T03:16:30.7142047Z #15 53.41     at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
2026-02-11T03:16:30.7143461Z #15 53.41     at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrations()
2026-02-11T03:16:30.7166959Z #15 53.41     at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.Internal.NpgsqlHistoryRepository.GetAppliedMigrations()
2026-02-11T03:16:30.7169824Z #15 53.41     at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetAppliedMigrations(DatabaseFacade databaseFacade)
2026-02-11T03:16:30.7171553Z #15 53.41     at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetPendingMigrations(DatabaseFacade databaseFacade)
2026-02-11T03:16:30.7173487Z #15 53.41     at BackendService.Infrastructure.DbContextExtensions.ApplyMigrations(WebApplication app) in /src/BackendService/Infrastructure/DbContextExtensions.cs:43
2026-02-11T03:16:30.7186894Z #15 53.41     at Program.<Main>$(String[] args) in /src/BackendService/Program.cs:60
2026-02-11T03:16:30.7188487Z #15 53.41     at InvokeStub_Program.<Main>$(Object, Span`1)
2026-02-11T03:16:30.7189725Z #15 53.41     at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2026-02-11T03:16:30.7191002Z #15 53.41     --- End of stack trace from previous location ---
2026-02-11T03:16:30.7192100Z #15 53.41     at Microsoft.AspNetCore.Mvc.Testing.DeferredHostBuilder.DeferredHost.StartAsync(CancellationToken cancellationToken)
2026-02-11T03:16:30.7199411Z #15 53.41     at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Start(IHost host)
2026-02-11T03:16:30.7200630Z #15 53.41     at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateHost(IHostBuilder builder)
2026-02-11T03:16:30.7201991Z #15 53.41     at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.ConfigureHostBuilder(IHostBuilder hostBuilder)
2026-02-11T03:16:30.7203303Z #15 53.41     at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.StartServer()
2026-02-11T03:16:30.7210083Z #15 53.41     at BackendService.Tests.TestWebServer.InitializeAsync() in /src/BackendService.Tests/TestWebServer.cs:72
2026-02-11T03:16:30.7211202Z #15 53.42   --->  System.Net.Sockets.SocketException: Connection refused
2026-02-11T03:16:30.7212006Z #15 53.42     at Npgsql.Internal.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
2026-02-11T03:16:30.7212651Z #15 53.42   Standard output
2026-02-11T03:16:30.7224179Z #15 53.42     fail: Microsoft.EntityFrameworkCore.Database.Connection[20004] An error occurred using the connection to database 'postgres' on server 'tcp://localhost:5435'.
2026-02-11T03:16:30.7226239Z #15 53.42     fail: Microsoft.EntityFrameworkCore.Database.Connection[20004] An error occurred using the connection to database 'postgres' on server 'tcp://localhost:5435'.

Additional Context

No response

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions