Fase 8 — Apprendimento #109
No files matched your search
@@ -236,7 +236,7 @@ public sealed class OkxTests
|
||||
return socket;
|
||||
});
|
||||
|
||||
using var stop = new CancellationTokenSource(TimeSpan.FromSeconds(20));
|
||||
using var stop = new CancellationTokenSource(TimeSpan.FromSeconds(60));
|
||||
var reading = Task.Run(async () =>
|
||||
{
|
||||
await foreach (var item in okx.StreamAsync(["BTC-EUR"], stop.Token).ConfigureAwait(false))
|
||||
@@ -262,7 +262,7 @@ public sealed class OkxTests
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -178,16 +178,37 @@ internal sealed class TestDb : IAsyncDisposable
|
||||
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()
|
||||
{
|
||||
await Db.DisposeAsync().ConfigureAwait(false);
|
||||
if (_postgresName is not null)
|
||||
{
|
||||
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 {_postgresName} WITH (FORCE)";
|
||||
await command.ExecuteNonQueryAsync().ConfigureAwait(false);
|
||||
await DropAsync(_postgresName).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (_folder is not null)
|
||||
|
||||
Reference in new issue
Block a user