Correzione: il motore non rimette a riposo la pagina che Alberto ha appena ripreso
Le prove di BrowserStartPageTests fallivano a volte (pagina «about:blank» invece della pagina iniziale, o la pagina iniziale invece di quella aperta da Alberto). Non era l'attesa del browser di #67: la stessa corsa si vede anche con il codice di main. Dopo «Ho finito» il giro del motore vede che Alberto ha lasciato il browser e chiede il turno della pagina per il riposo; se nel frattempo Alberto riprende il browser e la sua navigazione prende il turno per prima, il riposo arriva subito dopo e gli porta via la pagina (una finestra bianca, #52). Ora il riposo dopo la guida e quello di fine sessione guardano di nuovo, con il turno in mano, se Alberto guida (o se una verifica tiene la pagina), come fa già la ricerca dei profili; il riposo resta dovuto per quando lascia il browser. Nuova prova deterministica in EngineHostTests. Il motore conta come avviato già in StartAsync, non solo quando il pool di thread arriva al suo giro: «Scollega» che fallisce lo dice subito (l'altra prova che falliva a volte, DesktopCompositionTests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8d1b344366
commit
98769b5870
2 files changed
+75
-3
No files matched your search
@@ -74,7 +74,10 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
|
||||
internal IReadOnlyList<RecentAction> RecentActions(int limit) => _recent.Snapshot(limit);
|
||||
|
||||
/// <summary>Starts the background loop.</summary>
|
||||
/// <summary>
|
||||
/// Starts the background loop. It counts as running from here (<see cref="EngineRuntime.IsRunning"/>), not only once
|
||||
/// the thread pool gets to it: whoever started it (Febe's start, «Scollega») says so right away.
|
||||
/// </summary>
|
||||
public Task StartAsync(CancellationToken ct = default)
|
||||
{
|
||||
lock (_gate)
|
||||
@@ -86,6 +89,7 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
|
||||
_loopCts = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
var token = _loopCts.Token;
|
||||
_s.Runtime.IsRunning = true;
|
||||
_loop = Task.Run(() => RunAsync(token), CancellationToken.None);
|
||||
}
|
||||
|
||||
@@ -739,8 +743,11 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
{
|
||||
try
|
||||
{
|
||||
await _runner.RestAsync(ct).ConfigureAwait(false);
|
||||
s.PageTurns.NoteRested();
|
||||
if (!KeepsPageAfterWaitingForTurn())
|
||||
{
|
||||
await _runner.RestAsync(ct).ConfigureAwait(false);
|
||||
s.PageTurns.NoteRested();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
@@ -797,6 +804,23 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
s.Events.Publish(EngineNotificationKind.StateChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looked at again with the page turn in hand, right before a rest of the engine: the turn may have come only after
|
||||
/// Alberto's own navigation, which takes it too (he took the browser again right after letting go of it), or after a
|
||||
/// verification. Then the page is his, or must stay as it is (spec §6.1, §7.6): no rest, and the rest is owed for
|
||||
/// when he lets go. The profile search looks again in the same way before its own rest.
|
||||
/// </summary>
|
||||
private bool KeepsPageAfterWaitingForTurn()
|
||||
{
|
||||
if (_s.Runtime.UserIsDriving)
|
||||
{
|
||||
Volatile.Write(ref _restAfterDriving, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return _s.Breaker.State.Status is BreakerStatus.Challenge or BreakerStatus.Disconnected;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alberto let go of the browser and no session runs: the page goes back to rest (spec §6.1), so that nothing he or a
|
||||
/// cancelled session left open stays on the site — a story viewer moves on by itself to other accounts (§6.3).
|
||||
@@ -821,6 +845,11 @@ public sealed class EngineHost : IAsyncDisposable
|
||||
|
||||
await using (turn.ConfigureAwait(false))
|
||||
{
|
||||
if (KeepsPageAfterWaitingForTurn())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await _runner.RestAsync(ct).ConfigureAwait(false);
|
||||
_s.PageTurns.NoteRested();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user