Retry test database creation on any transient PostgreSQL error (refs #33)
ci / test (postgres) (push) Successful in 3m40s
ci / test (sqlite) (push) Successful in 2m53s
ci / test (postgres) (pull_request) Successful in 4m31s
ci / test (sqlite) (pull_request) Successful in 2m59s
ci / image (push) Successful in 13s
ci / image (pull_request) Successful in 15s
ci / test (postgres) (push) Successful in 3m40s
ci / test (sqlite) (push) Successful in 2m53s
ci / test (postgres) (pull_request) Successful in 4m31s
ci / test (sqlite) (pull_request) Successful in 2m59s
ci / image (push) Successful in 13s
ci / image (pull_request) Successful in 15s
CI run 188 failed once on the SQLite job: a cross-engine test lost its connection (EndOfStreamException) while creating its PostgreSQL database, right after the service container started. The retry covered only timeouts. It now covers every transient Npgsql error and picks a new database name on each attempt, in case the lost answer had already created the database. Test helper only; no product code changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1a0912e436
commit
16be51e175
1 file changed
+6
-4
@@ -136,9 +136,11 @@ internal sealed class TestDb : IAsyncDisposable
|
||||
return new TestDb(new() { Engine = engine, SqlitePath = Path.Combine(folder, "test.sqlite3") }, folder, null);
|
||||
}
|
||||
|
||||
var name = "anubis_t_" + Guid.NewGuid().ToString("N");
|
||||
string name;
|
||||
for (var attempt = 1; ; attempt++)
|
||||
{
|
||||
// A new name each time: a dropped connection may have created the database before the answer was lost.
|
||||
name = "anubis_t_" + Guid.NewGuid().ToString("N");
|
||||
try
|
||||
{
|
||||
await using var admin = Anubis.Db.Database.Open(AdminSettings());
|
||||
@@ -148,10 +150,10 @@ internal sealed class TestDb : IAsyncDisposable
|
||||
await command.ExecuteNonQueryAsync().ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
catch (Npgsql.NpgsqlException ex) when (ex.InnerException is TimeoutException && attempt < 4)
|
||||
catch (Npgsql.NpgsqlException ex) when (ex.IsTransient && attempt < 4)
|
||||
{
|
||||
// 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.
|
||||
// Many tests create their database at once and a busy CI runner can be slow to accept, or drop a
|
||||
// connection while its PostgreSQL service is still settling. That is the runner, not the code under test.
|
||||
await Task.Delay(TimeSpan.FromSeconds(attempt)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user