Prove che cadevano con il runner carico (#46)
Le prove cadevano a ogni carico della CI, ogni volta prove diverse. Dietro alcune c'erano difetti veri: FebeDatabase lasciava i file aperti dopo DisposeAsync (comandi SQLite non chiusi, pool di lettura chiuso dopo lo scrittore), e il WAL spariva durante lo spostamento della cartella Dati; la scheda dell'account senza statistiche leggeva i file di tutta la libreria; l'arresto di FebeApp non aspettava i lavori aggiunti da un avvio in corso. Chromium ha 120 s per avviarsi e aprire la prima scheda, e il ricollegamento smette appena il processo cambia. Nelle prove i limiti di tempo diventano protezioni contro un blocco: attese per condizione con un aiuto comune, limiti per classe nella prova di scala con il tempo migliore, porta 0 e stderr di Chromium nel browser delle prove, e la prova di «Scollega» di WebView2 controlla che il processo esca davvero. Provato su Windows con tutti i core occupati. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e2e64c09e8
commit
0775a1460f
34 files changed
+875
-245
No files matched your search
@@ -37,7 +37,7 @@ public sealed partial class ServerEndToEndTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(360_000, CooperativeCancellation = true)]
|
||||
[Timeout(540_000, CooperativeCancellation = true)]
|
||||
public async Task TheRealServerCollectsFromTheTestSiteStopsAtTheVerificationAndShowsTheBrowser()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
@@ -46,7 +46,7 @@ public sealed partial class ServerEndToEndTests
|
||||
await using var bed = await ServerTestBed.StartAsync(telegram: telegram, freeSpace: disk);
|
||||
var server = bed.Server;
|
||||
Assert.IsEmpty(server.Problems);
|
||||
await server.Running.WaitAsync(TimeSpan.FromSeconds(60), ct);
|
||||
await bed.WaitRunningAsync(ct);
|
||||
var connection = server.Connection!;
|
||||
|
||||
// The health check answers without a session; everything else wants the password.
|
||||
@@ -204,13 +204,13 @@ public sealed partial class ServerEndToEndTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(120_000, CooperativeCancellation = true)]
|
||||
[Timeout(360_000, CooperativeCancellation = true)]
|
||||
public async Task FinishWithoutSessionSaysSoAndDisconnectDeletesTheProfile()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ServerTestBed.StartAsync(autoLogin: true);
|
||||
var server = bed.Server;
|
||||
await server.Running.WaitAsync(TimeSpan.FromSeconds(60), ct);
|
||||
await bed.WaitRunningAsync(ct);
|
||||
var connection = server.Connection!;
|
||||
Assert.AreEqual(ConnectionState.Connected, (await connection.GetStatusAsync(ct)).State, "the test site's automatic login");
|
||||
|
||||
@@ -222,7 +222,10 @@ public sealed partial class ServerEndToEndTests
|
||||
Assert.IsTrue(server.Browser.IsAvailable, "the browser runs again, with an empty profile");
|
||||
Assert.AreEqual(ConnectionState.NotConnected, (await connection.GetStatusAsync(ct)).State);
|
||||
Assert.IsFalse(server.Browser.UserIsDriving);
|
||||
Assert.IsTrue(server.Engine!.Services.Runtime.IsRunning || await WaitRunningAsync(server), "the engine loop runs again (and waits for a connection)");
|
||||
await ServerTestBed.WaitUntilAsync(
|
||||
() => Task.FromResult(server.Engine!.Services.Runtime.IsRunning),
|
||||
TimeSpan.FromSeconds(60),
|
||||
"il motore di nuovo in funzione, in attesa del collegamento");
|
||||
|
||||
// «Ho finito» without having logged in: Febe says it does not find the session.
|
||||
await connection.BeginUserDrivingAsync(openLogin: false, ct);
|
||||
@@ -243,13 +246,13 @@ public sealed partial class ServerEndToEndTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(120_000, CooperativeCancellation = true)]
|
||||
[Timeout(420_000, CooperativeCancellation = true)]
|
||||
public async Task TwoViewsOpenedAtTheSameMomentLeaveOneViewWithItsFramesAndOneLease()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ServerTestBed.StartAsync();
|
||||
var server = bed.Server;
|
||||
await server.Running.WaitAsync(TimeSpan.FromSeconds(60), ct);
|
||||
await bed.WaitRunningAsync(ct);
|
||||
var host = server.RemoteView!;
|
||||
var gate = server.Browser!.UserDriving;
|
||||
var released = 0;
|
||||
@@ -268,7 +271,7 @@ public sealed partial class ServerEndToEndTests
|
||||
// «about:blank» here means the engine's rest has committed.
|
||||
await ServerTestBed.WaitUntilAsync(
|
||||
async () => await Febe.Browser.Cdp.CdpPageExtensions.GetMainFrameUrlAsync(server.Browser.Cdp, ct) == "about:blank",
|
||||
TimeSpan.FromSeconds(20),
|
||||
TimeSpan.FromSeconds(60),
|
||||
"la pagina di riposo");
|
||||
|
||||
// Two tabs restored together, or the phone and the PC at once: the newest wins, the other is ended — and the
|
||||
@@ -302,13 +305,13 @@ public sealed partial class ServerEndToEndTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(180_000, CooperativeCancellation = true)]
|
||||
[Timeout(480_000, CooperativeCancellation = true)]
|
||||
public async Task AViewOpenedWhileThePageIsNavigatingOpensAndShowsItsFrames()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ServerTestBed.StartAsync();
|
||||
var server = bed.Server;
|
||||
await server.Running.WaitAsync(TimeSpan.FromSeconds(60), ct);
|
||||
await bed.WaitRunningAsync(ct);
|
||||
var host = server.RemoteView!;
|
||||
var browser = server.Browser!;
|
||||
|
||||
@@ -318,7 +321,7 @@ public sealed partial class ServerEndToEndTests
|
||||
// engine's rest after the last view has committed and nothing else navigates.
|
||||
await ServerTestBed.WaitUntilAsync(
|
||||
async () => await Febe.Browser.Cdp.CdpPageExtensions.GetMainFrameUrlAsync(browser.Cdp, ct) == "about:blank",
|
||||
TimeSpan.FromSeconds(20),
|
||||
TimeSpan.FromSeconds(60),
|
||||
"la pagina di riposo");
|
||||
|
||||
// Even rounds: «Accedi a Instagram» on the Collegamento page navigates to the login page while the same page
|
||||
@@ -353,7 +356,7 @@ public sealed partial class ServerEndToEndTests
|
||||
private static async Task<bool> FrameArrivesAsync(IRemoteViewConnection view, CancellationToken ct)
|
||||
{
|
||||
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
timeout.CancelAfter(TimeSpan.FromSeconds(15));
|
||||
timeout.CancelAfter(TimeSpan.FromSeconds(60)); // only a hang guard: it returns at the first frame
|
||||
try
|
||||
{
|
||||
await foreach (var output in view.ReadAsync(timeout.Token))
|
||||
@@ -371,16 +374,6 @@ public sealed partial class ServerEndToEndTests
|
||||
return false;
|
||||
}
|
||||
|
||||
private static async Task<bool> WaitRunningAsync(Febe.Server.FebeServer server)
|
||||
{
|
||||
for (var i = 0; i < 40 && !server.Engine!.Services.Runtime.IsRunning; i++)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
return server.Engine!.Services.Runtime.IsRunning;
|
||||
}
|
||||
|
||||
private static async Task<List<(Entry Entry, Media Media)>> StoredAsync(Febe.Server.FebeServer server, long accountId, CancellationToken ct)
|
||||
{
|
||||
var list = new List<(Entry, Media)>();
|
||||
|
||||
@@ -9,8 +9,22 @@ namespace Febe.Tests.Server.Support;
|
||||
internal sealed class FakeRemoteViewHost : IRemoteViewHost
|
||||
{
|
||||
private readonly Lock _gate = new();
|
||||
private readonly List<FakeRemoteViewConnection> _opened = [];
|
||||
|
||||
public List<FakeRemoteViewConnection> Opened { get; } = [];
|
||||
/// <summary>
|
||||
/// The views opened so far, copied under the lock the server writes with: the tests read it from their own thread
|
||||
/// while the server may be adding to it (#46).
|
||||
/// </summary>
|
||||
public IReadOnlyList<FakeRemoteViewConnection> Opened
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
return [.. _opened];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Unavailable { get; set; }
|
||||
|
||||
@@ -24,12 +38,12 @@ internal sealed class FakeRemoteViewHost : IRemoteViewHost
|
||||
var connection = new FakeRemoteViewConnection();
|
||||
lock (_gate)
|
||||
{
|
||||
if (Opened.LastOrDefault() is { Disposed: false } previous)
|
||||
if (_opened.LastOrDefault() is { Disposed: false } previous)
|
||||
{
|
||||
previous.End(RemoteViewEnd.Replaced);
|
||||
}
|
||||
|
||||
Opened.Add(connection);
|
||||
_opened.Add(connection);
|
||||
}
|
||||
|
||||
return Task.FromResult<IRemoteViewConnection>(connection);
|
||||
@@ -39,12 +53,24 @@ internal sealed class FakeRemoteViewHost : IRemoteViewHost
|
||||
internal sealed class FakeRemoteViewConnection : IRemoteViewConnection
|
||||
{
|
||||
private readonly Channel<RemoteViewOutput> _output = Channel.CreateUnbounded<RemoteViewOutput>();
|
||||
private volatile bool _disposed;
|
||||
private volatile object? _ended;
|
||||
|
||||
public ConcurrentQueue<object> Inputs { get; } = new();
|
||||
|
||||
public bool Disposed { get; private set; }
|
||||
/// <summary>Set by the server's thread, read by the test's: volatile.</summary>
|
||||
public bool Disposed
|
||||
{
|
||||
get => _disposed;
|
||||
private set => _disposed = value;
|
||||
}
|
||||
|
||||
public RemoteViewEnd? Ended
|
||||
{
|
||||
get => (RemoteViewEnd?)_ended;
|
||||
private set => _ended = value;
|
||||
}
|
||||
|
||||
public RemoteViewEnd? Ended { get; private set; }
|
||||
|
||||
public void Write(RemoteViewOutput output) => _output.Writer.TryWrite(output);
|
||||
|
||||
|
||||
@@ -163,7 +163,30 @@ internal sealed class ServerTestBed : IAsyncDisposable
|
||||
|
||||
public ThumbnailStore Thumbnails => new(Server.Data!.Thumbnails);
|
||||
|
||||
/// <summary>
|
||||
/// The hang guard of <see cref="WaitRunningAsync"/>. A cold Chromium start on a loaded runner can take minutes,
|
||||
/// with a retry after a failed attempt (#46); the wait ends as soon as Febe is up.
|
||||
/// </summary>
|
||||
public static readonly TimeSpan RunningPatience = TimeSpan.FromMinutes(4);
|
||||
|
||||
/// <summary>
|
||||
/// Waits until Febe has started (Xvfb, Chromium, pipeline, connection, engine). A start that never ends fails with
|
||||
/// the last error of the browser instead of a bare timeout.
|
||||
/// </summary>
|
||||
public async Task WaitRunningAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Server.Running.WaitAsync(RunningPatience, ct);
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
Assert.Fail($"Febe non è partito in {RunningPatience.TotalMinutes:0} minuti: {Server.Browser?.LastError ?? "nessun errore del browser"}.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Waits (real time) until <paramref name="condition"/> holds; fails with <paramref name="what"/> otherwise.</summary>
|
||||
|
||||
public static async Task WaitUntilAsync(Func<Task<bool>> condition, TimeSpan timeout, string what)
|
||||
{
|
||||
var deadline = DateTime.UtcNow + timeout;
|
||||
|
||||
Reference in new issue
Block a user