Public Access
Stop a dead WebView2 hanging Connect with the busy flag stuck
VaultViewModel.ConnectAsync awaited TerminalWorkspace.WaitForRendererAsync
with no timeout and no token, and RunAsync clears IsBusy only after the
work returns. Whether the renderer attaches at all depends on a runtime
this application does not install: with a missing or policy-blocked
Evergreen runtime, or an AppContainer that cannot reach loopback, the
socket never arrives — so Connect never returned, the window stayed
disabled on "Connecting…" for the rest of the session, and nothing on
screen said why. Left out of 0500e43 to keep that change focused, and
recorded in docs/platform-flags.md as worth fixing on its own merits.
The gate itself is unchanged and has to stay: TerminalDataPlane.SendAsync
drops frames when no renderer is attached rather than queueing them, so a
session opened before the renderer arrives loses its SessionOpened frame
and then streams output at a terminal that was never created. Only the
wait changed — RendererAttached.WaitAsync(timeout, cancellationToken),
with the command's own token threaded through.
Fifteen seconds, on TerminalWorkspaceOptions.RendererTimeout. Attaching is
normally near-instant, since WebView2 starts with the window and the page
has usually attached while the passphrase was still being typed, but a
first run on a cold profile creates a user-data directory and starts a
process tree of some thirty-five processes first, which on a loaded
machine is seconds rather than milliseconds. A renderer that will never
attach will not attach however long the wait is, so being generous costs
only how long a broken runtime takes to say so, while being tight costs
telling someone their runtime is broken when it was merely slow.
Injectable because both new tests would otherwise sit out that budget.
The timeout is caught in VaultViewModel rather than left to RunAsync's
generic handler, because TimeoutException.Message is "The operation has
timed out" — which sends someone looking at their network or their host.
The status now names the WebView2 runtime and says to install it.
TerminalWorkspaceTests covers the half that was missing: the wait gives up
(329 ms against a 250 ms budget) and obeys its token (2 ms against a
five-minute one). Before the bound, the first of those would have hung
rather than failed. ShellFlowTests never starts its workspace, which from
the view model's side is indistinguishable from a WebView2 that failed to
initialise, so it asserts that the status names WebView2 and that IsBusy
is cleared; changing the catch to another exception type makes it fail
with "The operation has timed out.", so neither assertion is vacuous. The
success path is untouched and still covered end to end by
TerminalEndToEndTests against a real sshd container, which now passes the
test's cancellation token.
One byproduct: the doc comment on WaitForRendererAsync carried two
double-encoded em dashes, fixed now that the block is rewritten.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using System.Text;
|
||||
using DodoSSH.Client.Ssh;
|
||||
using NSubstitute;
|
||||
|
||||
namespace DodoSSH.Client.Terminal.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// The renderer gate: the one place the workspace waits on something outside the process.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The gate itself is not in question. <see cref="TerminalDataPlane.SendAsync"/> drops frames when nothing
|
||||
/// is attached, so a session opened before the renderer arrives loses its <c>SessionOpened</c> frame and
|
||||
/// streams output at a terminal that was never created — and that it opens when a renderer does attach is
|
||||
/// covered by <see cref="TerminalDataPlaneTests.TheRenderer_Attaches"/>. What is worth a test here is the
|
||||
/// half that used to be missing: waiting for a renderer that never arrives has to end.
|
||||
/// </remarks>
|
||||
public sealed class TerminalWorkspaceTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task WaitingForARendererThatNeverAttaches_GivesUp()
|
||||
{
|
||||
// The shipped failure this stands in for is a WebView2 that never initialises — no Evergreen
|
||||
// runtime, an install blocked by policy, an AppContainer that cannot reach loopback. From this
|
||||
// side they are identical and all look like the listener being up with nothing ever connecting
|
||||
// to it. Before the wait was bounded this test would have hung instead of failing.
|
||||
await using var workspace = CreateWorkspace(TimeSpan.FromMilliseconds(250));
|
||||
workspace.Start();
|
||||
|
||||
await Should.ThrowAsync<TimeoutException>(async () =>
|
||||
await workspace.WaitForRendererAsync(TestContext.Current.CancellationToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WaitingForARenderer_ObeysItsCancellationToken()
|
||||
{
|
||||
// The timeout is the backstop; the caller's token is what makes a Connect the user gave up on
|
||||
// return at once rather than sitting out the rest of the wait. The timeout here is long enough
|
||||
// that only cancellation can end this.
|
||||
await using var workspace = CreateWorkspace(TimeSpan.FromMinutes(5));
|
||||
workspace.Start();
|
||||
|
||||
using var cancellation = new CancellationTokenSource();
|
||||
var wait = workspace.WaitForRendererAsync(cancellation.Token);
|
||||
|
||||
await cancellation.CancelAsync();
|
||||
|
||||
await Should.ThrowAsync<OperationCanceledException>(async () => await wait);
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// The connection factory is never reached: every test here stops at the gate, and reaching a real
|
||||
/// host would make this a network test.
|
||||
/// </remarks>
|
||||
private static TerminalWorkspace CreateWorkspace(TimeSpan rendererTimeout) =>
|
||||
new(
|
||||
new InMemoryTerminalAssetProvider(
|
||||
new Dictionary<string, TerminalAsset>(StringComparer.Ordinal)
|
||||
{
|
||||
[TerminalDataPlane.PagePath] = new(
|
||||
"text/html; charset=utf-8",
|
||||
Encoding.UTF8.GetBytes("<html><body></body></html>")),
|
||||
}),
|
||||
Substitute.For<ISshConnectionFactory>(),
|
||||
TimeProvider.System,
|
||||
new TerminalWorkspaceOptions { RendererTimeout = rendererTimeout });
|
||||
}
|
||||
Reference in New Issue
Block a user