From 16be51e17594ceed6b37e8482f1cf3bae24b4714 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Tue, 10 Nov 2026 22:09:16 +0100 Subject: [PATCH] Retry test database creation on any transient PostgreSQL error (refs #33) 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 --- tests/Anubis.Tests/TestSupport.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/Anubis.Tests/TestSupport.cs b/tests/Anubis.Tests/TestSupport.cs index 0749eb3..36ee6d7 100644 --- a/tests/Anubis.Tests/TestSupport.cs +++ b/tests/Anubis.Tests/TestSupport.cs @@ -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); } }