Browser di Febe per Windows: all'uscita l'avvio non resta appeso a WebView2
Il limite di 30 s all'arresto copriva solo un «Scollega» in corso (rilievo R3 della revisione). FebeApp aspetta RunAsync prima di chiudere il browser, e RunAsync e il ciclo di ripartenza aspettavano WebView2 senza limite: con un WebView2 che non risponde, «Esci» restava fermo. Ora WebView2Host.StartAsync onora il suo token. Chi chiama smette subito di aspettare, un avvio non ancora cominciato non comincia più, uno in corso finisce da sé e chiude ciò che ha creato se l'arresto è già passato. Il ciclo di ripartenza usa lo stesso avvio, e WebView2Browser.DisposeAsync lo aspetta al più 30 s. «Scollega», una volta cominciato, va invece fino in fondo: il profilo con la sessione deve sparire e il motore deve ripartire. Nuova prova: con il thread dell'interfaccia occupato, RunAsync torna subito alla cancellazione e dopo l'uscita non si apre nessuna finestra. Rossa prima della correzione (ancora in attesa dopo 10 s), verde dopo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a144d611ac
commit
7aaa93fe3b
4 files changed
+106
-6
No files matched your search
@@ -186,6 +186,60 @@ public sealed class WebView2LifecycleTests
|
||||
Assert.HasCount(2, bed.Lines.Lines.Where(l => l.Contains("ERRORE", StringComparison.Ordinal)), "only the two failed starts: " + bed.Lines.Text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// «Esci» while the start does not complete (review of 20 October 2026): the composition awaits
|
||||
/// <see cref="Febe.Desktop.Browser.WebView2Browser.RunAsync"/> before it closes the browser, so RunAsync must stop
|
||||
/// waiting as soon as it is cancelled. Here the UI thread is kept busy, as when WebView2 does not answer.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
[Timeout(120_000, CooperativeCancellation = true)]
|
||||
public async Task OnExitTheStartStopsWaitingForAUiThreadThatDoesNotAnswer()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await BrowserBed.CreateAsync("uscita");
|
||||
var released = false;
|
||||
var busy = bed.Ui.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
// Thread.Sleep does not pump: nothing else runs on the UI thread meanwhile.
|
||||
var until = DateTime.UtcNow.AddSeconds(60);
|
||||
while (!Volatile.Read(ref released) && DateTime.UtcNow < until)
|
||||
{
|
||||
Thread.Sleep(20);
|
||||
}
|
||||
});
|
||||
|
||||
using var lifetime = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
var run = Task.Run(() => bed.Browser.RunAsync(lifetime.Token), ct);
|
||||
await Task.Delay(500, ct);
|
||||
Assert.IsFalse(run.IsCompleted, "the start waits for the UI thread");
|
||||
|
||||
// «Esci»: FebeApp cancels its lifetime, then waits for RunAsync.
|
||||
var watch = Stopwatch.StartNew();
|
||||
await lifetime.CancelAsync();
|
||||
try
|
||||
{
|
||||
await run.WaitAsync(TimeSpan.FromSeconds(10), ct);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Volatile.Write(ref released, true);
|
||||
await busy.Task;
|
||||
}
|
||||
|
||||
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.IsFalse(bed.Browser.IsAvailable);
|
||||
|
||||
// The start that was waiting for the UI thread does not begin after the exit, and stopping is quick.
|
||||
watch.Restart();
|
||||
await bed.Browser.DisposeAsync();
|
||||
Assert.IsLessThan(10, watch.Elapsed.TotalSeconds);
|
||||
Assert.IsNull(await bed.OnUiAsync(() => bed.Browser.Host.Window), "no window was created after the exit");
|
||||
Assert.AreEqual(0, bed.Browser.Host.BrowserProcessId, "no browser process was started after the exit");
|
||||
Assert.IsFalse(bed.Lines.Any("ERRORE"), bed.Lines.Text);
|
||||
Assert.IsFalse(bed.Lines.Any("Browser di Febe pronto"), bed.Lines.Text);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(180_000, CooperativeCancellation = true)]
|
||||
public async Task WhenItsBrowserProcessDiesTheBrowserStartsAgainByItself()
|
||||
|
||||
Reference in new issue
Block a user