Let the tests ride out a busy server
ci / test (postgres) (push) Successful in 5m36s
ci / test (sqlite) (push) Successful in 7m14s
ci / test (postgres) (pull_request) Successful in 5m57s
ci / test (sqlite) (pull_request) Successful in 7m11s
ci / image (push) Successful in 1m21s
ci / image (pull_request) Successful in 59s

On a loaded runner a forced DROP DATABASE gave up on an autovacuum slow to
leave, and failed a test that had already passed: the cleanup is tried again, as
the creation already is. The feed test gets time for its slow reader on a
computer at full load.

refs #67

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 15:16:39 +01:00
1 parent c7e462b6f4
commit 3eabc7713e
2 files changed
+28 -7

No files matched your search

+2 -2
View File
@@ -236,7 +236,7 @@ public sealed class OkxTests
return socket; return socket;
}); });
using var stop = new CancellationTokenSource(TimeSpan.FromSeconds(20)); using var stop = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var reading = Task.Run(async () => var reading = Task.Run(async () =>
{ {
await foreach (var item in okx.StreamAsync(["BTC-EUR"], stop.Token).ConfigureAwait(false)) await foreach (var item in okx.StreamAsync(["BTC-EUR"], stop.Token).ConfigureAwait(false))
@@ -262,7 +262,7 @@ public sealed class OkxTests
publicSocket.Push(ticker); publicSocket.Push(ticker);
} }
await reading.WaitAsync(TimeSpan.FromSeconds(10)).ConfigureAwait(false); await reading.WaitAsync(TimeSpan.FromSeconds(30)).ConfigureAwait(false);
Assert.IsTrue(sockets.All(s => s.Disposed)); Assert.IsTrue(sockets.All(s => s.Disposed));
} }
+26 -5
View File
@@ -178,16 +178,37 @@ internal sealed class TestDb : IAsyncDisposable
ConnectTimeoutSeconds = 30, ConnectTimeoutSeconds = 30,
}; };
/// <summary>
/// Forced, a drop still waits only five seconds for the sessions it ends, and on a busy server an autovacuum can
/// take longer to leave ("is being accessed by other users"), or the answer can arrive late. That is the server,
/// not the code under test: the drop is tried again.
/// </summary>
private static async Task DropAsync(string name)
{
for (var attempt = 1; ; attempt++)
{
try
{
await using var admin = Anubis.Db.Database.Open(AdminSettings());
await using var connection = await admin.OpenConnectionAsync(CancellationToken.None).ConfigureAwait(false);
await using var command = connection.CreateCommand();
command.CommandText = $"DROP DATABASE IF EXISTS {name} WITH (FORCE)";
await command.ExecuteNonQueryAsync().ConfigureAwait(false);
return;
}
catch (Npgsql.NpgsqlException ex) when (attempt < 4 && (ex.IsTransient || ex.SqlState == Npgsql.PostgresErrorCodes.ObjectInUse))
{
await Task.Delay(TimeSpan.FromSeconds(attempt)).ConfigureAwait(false);
}
}
}
public async ValueTask DisposeAsync() public async ValueTask DisposeAsync()
{ {
await Db.DisposeAsync().ConfigureAwait(false); await Db.DisposeAsync().ConfigureAwait(false);
if (_postgresName is not null) if (_postgresName is not null)
{ {
await using var admin = Anubis.Db.Database.Open(AdminSettings()); await DropAsync(_postgresName).ConfigureAwait(false);
await using var connection = await admin.OpenConnectionAsync(CancellationToken.None).ConfigureAwait(false);
await using var command = connection.CreateCommand();
command.CommandText = $"DROP DATABASE IF EXISTS {_postgresName} WITH (FORCE)";
await command.ExecuteNonQueryAsync().ConfigureAwait(false);
} }
if (_folder is not null) if (_folder is not null)