Give test databases a longer PostgreSQL connect timeout (refs #20 #25)
ci / test (postgres) (push) Successful in 2m37s
ci / test (sqlite) (push) Successful in 2m4s
ci / test (postgres) (pull_request) Successful in 3m17s
ci / test (sqlite) (pull_request) Successful in 2m22s
ci / image (push) Successful in 35s
ci / image (pull_request) Successful in 11s
ci / test (postgres) (push) Successful in 2m37s
ci / test (sqlite) (push) Successful in 2m4s
ci / test (postgres) (pull_request) Successful in 3m17s
ci / test (sqlite) (pull_request) Successful in 2m22s
ci / image (push) Successful in 35s
ci / image (pull_request) Successful in 11s
On the CI runner twelve test workers open PostgreSQL connections at once and some waited longer than the application's 5 seconds, failing two collector tests with a connection timeout that has nothing to do with the code under test. The connect timeout is now a DbSettings field that keeps the 5-second default for the application, and the test databases ask for 30 seconds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
094a527ba2
commit
1a8d48212f
3 files changed
+10
-3
No files matched your search
@@ -79,7 +79,7 @@ public sealed class Database : IAsyncDisposable
|
|||||||
Username = settings.User,
|
Username = settings.User,
|
||||||
Password = settings.Password,
|
Password = settings.Password,
|
||||||
};
|
};
|
||||||
pg.Timeout = 5;
|
pg.Timeout = settings.ConnectTimeoutSeconds;
|
||||||
pg.CommandTimeout = 60;
|
pg.CommandTimeout = 60;
|
||||||
pg.ApplicationName = "anubis";
|
pg.ApplicationName = "anubis";
|
||||||
var dataSource = new NpgsqlDataSourceBuilder(pg.ToString()).Build();
|
var dataSource = new NpgsqlDataSourceBuilder(pg.ToString()).Build();
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ public sealed record DbSettings
|
|||||||
/// <summary>A full PostgreSQL address (<c>ANUBIS_DB_URL</c>) that replaces the five fields.</summary>
|
/// <summary>A full PostgreSQL address (<c>ANUBIS_DB_URL</c>) that replaces the five fields.</summary>
|
||||||
public string? Url { get; init; }
|
public string? Url { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Seconds to wait for a new PostgreSQL connection. Short, so a lost server shows quickly; tests raise it.</summary>
|
||||||
|
public int ConnectTimeoutSeconds { get; init; } = 5;
|
||||||
|
|
||||||
/// <summary>What the interface shows: engine and place, never the password.</summary>
|
/// <summary>What the interface shows: engine and place, never the password.</summary>
|
||||||
public string Describe() => Engine switch
|
public string Describe() => Engine switch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -150,8 +150,8 @@ internal sealed class TestDb : IAsyncDisposable
|
|||||||
}
|
}
|
||||||
catch (Npgsql.NpgsqlException ex) when (ex.InnerException is TimeoutException && attempt < 4)
|
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
|
// Many tests create their database at once and a busy CI runner can be slow to accept even within the
|
||||||
// application's 5-second connection timeout to accept one. That is the runner, not the code under test.
|
// longer test timeout. That is the runner, not the code under test.
|
||||||
await Task.Delay(TimeSpan.FromSeconds(attempt)).ConfigureAwait(false);
|
await Task.Delay(TimeSpan.FromSeconds(attempt)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,6 +170,10 @@ internal sealed class TestDb : IAsyncDisposable
|
|||||||
Database = "anubis",
|
Database = "anubis",
|
||||||
User = "anubis",
|
User = "anubis",
|
||||||
Password = PostgresPassword,
|
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()
|
public async ValueTask DisposeAsync()
|
||||||
|
|||||||
Reference in new issue
Block a user