diff --git a/src/Anubis/Db/Database.cs b/src/Anubis/Db/Database.cs index 350bdfb..2da0f35 100644 --- a/src/Anubis/Db/Database.cs +++ b/src/Anubis/Db/Database.cs @@ -79,7 +79,7 @@ public sealed class Database : IAsyncDisposable Username = settings.User, Password = settings.Password, }; - pg.Timeout = 5; + pg.Timeout = settings.ConnectTimeoutSeconds; pg.CommandTimeout = 60; pg.ApplicationName = "anubis"; var dataSource = new NpgsqlDataSourceBuilder(pg.ToString()).Build(); diff --git a/src/Anubis/Platform/StartupConfig.cs b/src/Anubis/Platform/StartupConfig.cs index 7d596ef..fd5c238 100644 --- a/src/Anubis/Platform/StartupConfig.cs +++ b/src/Anubis/Platform/StartupConfig.cs @@ -33,6 +33,9 @@ public sealed record DbSettings /// A full PostgreSQL address (ANUBIS_DB_URL) that replaces the five fields. public string? Url { get; init; } + /// Seconds to wait for a new PostgreSQL connection. Short, so a lost server shows quickly; tests raise it. + public int ConnectTimeoutSeconds { get; init; } = 5; + /// What the interface shows: engine and place, never the password. public string Describe() => Engine switch { diff --git a/tests/Anubis.Tests/TestSupport.cs b/tests/Anubis.Tests/TestSupport.cs index 8a1b776..0749eb3 100644 --- a/tests/Anubis.Tests/TestSupport.cs +++ b/tests/Anubis.Tests/TestSupport.cs @@ -150,8 +150,8 @@ internal sealed class TestDb : IAsyncDisposable } catch (Npgsql.NpgsqlException ex) when (ex.InnerException is TimeoutException && attempt < 4) { - // Many tests create their database at once: on a busy CI runner PostgreSQL can take longer than the - // application's 5-second connection timeout to accept one. That is the runner, not the code under test. + // Many tests create their database at once and a busy CI runner can be slow to accept even within the + // longer test timeout. That is the runner, not the code under test. await Task.Delay(TimeSpan.FromSeconds(attempt)).ConfigureAwait(false); } } @@ -170,6 +170,10 @@ internal sealed class TestDb : IAsyncDisposable Database = "anubis", User = "anubis", Password = PostgresPassword, + + // Twelve test workers open connections at once: on a busy CI runner PostgreSQL can take longer than the + // application's 5 seconds to accept one. Waiting longer here tests the same code without the runner's noise. + ConnectTimeoutSeconds = 30, }; public async ValueTask DisposeAsync()