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
@@ -137,9 +137,12 @@ public sealed class WebView2LifecycleTests
|
||||
/// browser, then the waiting attempt started a second WebView in the same window without closing the first. The
|
||||
/// orphan kept its browser process alive on the profile: the next «Scollega» waited 15 s for nothing and could not
|
||||
/// delete the profile (the Instagram session stayed on disk), and exiting waited 15 s more.
|
||||
/// The proof is what happens, not how long it takes (#46): an orphan keeps the browser process alive, so that process
|
||||
/// never exits and the profile stays. Under full CPU load a healthy process may report its exit after ExitWait
|
||||
/// (15 s), which a time limit could not tell from the orphan; the limits here only stop a hang.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
[Timeout(180_000, CooperativeCancellation = true)]
|
||||
[Timeout(420_000, CooperativeCancellation = true)]
|
||||
public async Task ScollegaWhileTheFirstStartWaitsToRetryLeavesOneWebViewAndTheNextScollegaWorks()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
@@ -150,7 +153,7 @@ public sealed class WebView2LifecycleTests
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(profile)!);
|
||||
await File.WriteAllTextAsync(profile, "occupa il posto della cartella del profilo", ct);
|
||||
var run = Task.Run(() => bed.Browser.RunAsync(ct), ct);
|
||||
await bed.WaitUntilAsync(() => bed.Lines.Any("Nuovo tentativo fra 15 s."), TimeSpan.FromSeconds(40), "il secondo avvio non riuscito", ct);
|
||||
await bed.WaitUntilAsync(() => bed.Lines.Any("Nuovo tentativo fra 15 s."), TimeSpan.FromSeconds(90), "il secondo avvio non riuscito", ct);
|
||||
File.Delete(profile);
|
||||
|
||||
// «Scollega» while RunAsync waits 15 s for its third attempt: the browser starts with it.
|
||||
@@ -159,30 +162,34 @@ public sealed class WebView2LifecycleTests
|
||||
var pid = bed.Browser.Host.BrowserProcessId;
|
||||
|
||||
// The waiting attempt finds the browser running: no second WebView, the one of «Scollega» untouched.
|
||||
await run.WaitAsync(TimeSpan.FromSeconds(40), ct);
|
||||
await run.WaitAsync(TimeSpan.FromSeconds(90), ct);
|
||||
var children = await bed.ChildWindowsAsync();
|
||||
Assert.HasCount(1, children, "one WebView in the window: " + string.Join(", ", children));
|
||||
Assert.AreEqual(pid, bed.Browser.Host.BrowserProcessId, "the browser process of «Scollega» is still the one in use");
|
||||
Assert.IsTrue(bed.Lines.Any("Browser di Febe pronto: WebView2 "), bed.Lines.Text);
|
||||
Assert.IsTrue(bed.Browser.IsAvailable);
|
||||
|
||||
// The next «Scollega»: the only browser process exits at once, the profile goes, the browser comes back.
|
||||
// The next «Scollega»: the only browser process exits, the profile goes, the browser comes back.
|
||||
var marker = Path.Combine(profile, "segno-della-prova");
|
||||
await File.WriteAllTextAsync(marker, "x", ct);
|
||||
using var first = Process.GetProcessById(pid);
|
||||
var watch = Stopwatch.StartNew();
|
||||
await Task.Run(() => bed.Browser.RestartWithEmptyProfileAsync(ct), ct);
|
||||
await Task.Run(() => bed.Browser.RestartWithEmptyProfileAsync(ct), ct).WaitAsync(HangGuard, ct);
|
||||
TestContext.WriteLine($"Secondo «Scollega»: {watch.Elapsed.TotalSeconds:0.0} s.");
|
||||
Assert.IsLessThan(10, watch.Elapsed.TotalSeconds, "no wait for a browser process that never exits");
|
||||
Assert.IsTrue(await HasExitedAsync(first, ct), "the browser process of the first «Scollega» exited: no orphan kept it alive");
|
||||
Assert.IsFalse(File.Exists(marker), "the profile with the session was deleted");
|
||||
Assert.HasCount(1, await bed.ChildWindowsAsync());
|
||||
Assert.IsTrue(bed.Browser.IsAvailable);
|
||||
var second = bed.Browser.Host.BrowserProcessId;
|
||||
Assert.AreNotEqual(pid, second, "a new browser process");
|
||||
using var last = Process.GetProcessById(second);
|
||||
|
||||
// Exiting closes the only WebView and its process exits: no wait in vain.
|
||||
// Exiting closes the only WebView and its process exits: nothing is left running.
|
||||
watch.Restart();
|
||||
await bed.Browser.DisposeAsync();
|
||||
await bed.Browser.DisposeAsync().AsTask().WaitAsync(HangGuard, ct);
|
||||
TestContext.WriteLine($"Arresto: {watch.Elapsed.TotalSeconds:0.0} s.");
|
||||
TestContext.WriteLine(bed.Lines.Text);
|
||||
Assert.IsLessThan(10, watch.Elapsed.TotalSeconds, "exiting waits for nothing");
|
||||
Assert.IsTrue(await HasExitedAsync(last, ct), "exiting leaves no browser process behind");
|
||||
Assert.HasCount(2, bed.Lines.Lines.Where(l => l.Contains("ERRORE", StringComparison.Ordinal)), "only the two failed starts: " + bed.Lines.Text);
|
||||
}
|
||||
|
||||
@@ -214,11 +221,15 @@ public sealed class WebView2LifecycleTests
|
||||
Assert.IsFalse(run.IsCompleted, "the start waits for the UI thread");
|
||||
|
||||
// «Esci»: FebeApp cancels its lifetime, then waits for RunAsync.
|
||||
// The proof is the order, not a time (#46): RunAsync returns while the UI thread is still busy, which it stays
|
||||
// until released below (or 60 s). The 30 s only bound a RunAsync that does wait for it.
|
||||
var watch = Stopwatch.StartNew();
|
||||
await lifetime.CancelAsync();
|
||||
bool uiStillBusy;
|
||||
try
|
||||
{
|
||||
await run.WaitAsync(TimeSpan.FromSeconds(10), ct);
|
||||
await run.WaitAsync(TimeSpan.FromSeconds(30), ct);
|
||||
uiStillBusy = !busy.Task.IsCompleted;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -227,7 +238,7 @@ public sealed class WebView2LifecycleTests
|
||||
}
|
||||
|
||||
TestContext.WriteLine($"RunAsync è tornato {watch.Elapsed.TotalSeconds:0.0} s dopo la cancellazione.");
|
||||
Assert.IsLessThan(3, watch.Elapsed.TotalSeconds, "RunAsync stops waiting at once");
|
||||
Assert.IsTrue(uiStillBusy, "RunAsync stops waiting at once, while the UI thread is still busy");
|
||||
Assert.IsFalse(bed.Browser.IsAvailable);
|
||||
|
||||
// The start that was waiting for the UI thread does not begin after the exit, and stopping is quick.
|
||||
@@ -240,6 +251,31 @@ public sealed class WebView2LifecycleTests
|
||||
Assert.IsFalse(bed.Lines.Any("Browser di Febe pronto"), bed.Lines.Text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Only against a hang: well above ExitWait of WebView2Host (15 s) and the retries of the profile deletion (5 s),
|
||||
/// so a slow but healthy machine never reaches it (#46).
|
||||
/// </summary>
|
||||
private static readonly TimeSpan HangGuard = TimeSpan.FromSeconds(90);
|
||||
|
||||
/// <summary>
|
||||
/// Whether a browser process exits, waiting for it by condition: a process that exits late under load is fine, one
|
||||
/// kept alive by an orphan WebView never exits and the guard ends the wait.
|
||||
/// </summary>
|
||||
private static async Task<bool> HasExitedAsync(Process process, CancellationToken ct)
|
||||
{
|
||||
using var guard = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
guard.CancelAfter(HangGuard);
|
||||
try
|
||||
{
|
||||
await process.WaitForExitAsync(guard.Token);
|
||||
return true;
|
||||
}
|
||||
catch (OperationCanceledException) when (!ct.IsCancellationRequested)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(180_000, CooperativeCancellation = true)]
|
||||
public async Task WhenItsBrowserProcessDiesTheBrowserStartsAgainByItself()
|
||||
|
||||
Reference in new issue
Block a user