Skip to content

Commit a3ba818

Browse files
Move OnIdle assertion into helper and drop list return
Small follow-up to review feedback: both call sites only ever asserted the handler variable became `$true`, so the `IReadOnlyList<bool>` return was needless ceremony. `AssertHandledAsync` now owns the assertion — it returns once the variable reports `$true` and otherwise fails via `Assert.Fail` when the ~15s poll window elapses, which reads as "the OnIdle handler never ran." `Assert.Fail` is fine here — we're on xUnit 2.9.3 and already use it in the E2E tests. No behavior change to what's being verified; the call sites just shrink to a single `await OnIdleTestHelpers.AssertHandledAsync(...)`. Still green on net8.0. Drafted by Copilot (Claude Opus 4.8). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f1393db commit a3ba818

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,25 @@ internal static class OnIdleTestHelpers
2828
// action and dispatches it asynchronously around subsequent pipeline executions.
2929
// So instead of sleeping a fixed amount, poll the handler variable until it
3030
// reports true (each read is itself a pipeline, giving the engine another chance
31-
// to drain the pending action). On timeout we return the last observed value so
32-
// the caller's assertion still fails loudly.
33-
internal static async Task<IReadOnlyList<bool>> WaitForHandledAsync(
34-
PsesInternalHost psesHost, string variableName)
31+
// to drain the pending action), and fail if it never does within the timeout.
32+
internal static async Task AssertHandledAsync(PsesInternalHost psesHost, string variableName)
3533
{
3634
using CancellationTokenSource cancellationSource = new(millisecondsDelay: 15000);
37-
IReadOnlyList<bool> handled = Array.Empty<bool>();
38-
while (true)
35+
while (!cancellationSource.IsCancellationRequested)
3936
{
40-
handled = await psesHost.ExecutePSCommandAsync<bool>(
37+
IReadOnlyList<bool> handled = await psesHost.ExecutePSCommandAsync<bool>(
4138
new PSCommand().AddScript(variableName),
4239
CancellationToken.None);
4340

44-
if ((handled.Count > 0 && handled[0]) || cancellationSource.IsCancellationRequested)
41+
if (handled.Count > 0 && handled[0])
4542
{
46-
return handled;
43+
return;
4744
}
4845

4946
await Task.Delay(200);
5047
}
48+
49+
Assert.Fail($"Timed out waiting for the OnIdle handler to set '{variableName}'.");
5150
}
5251
}
5352

@@ -235,9 +234,7 @@ await psesHost.ExecuteDelegateAsync(
235234
(_, _) => psesHost.OnPowerShellIdle(CancellationToken.None),
236235
CancellationToken.None);
237236

238-
handled = await OnIdleTestHelpers.WaitForHandledAsync(psesHost, "$handled");
239-
240-
Assert.Collection(handled, Assert.True);
237+
await OnIdleTestHelpers.AssertHandledAsync(psesHost, "$handled");
241238
}
242239

243240
[Fact]
@@ -330,9 +327,7 @@ await psesHost.ExecuteDelegateAsync(
330327
(_, _) => psesHost.OnPowerShellIdle(CancellationToken.None),
331328
CancellationToken.None);
332329

333-
IReadOnlyList<bool> handled = await OnIdleTestHelpers.WaitForHandledAsync(psesHost, "$handledInProfile");
334-
335-
Assert.Collection(handled, Assert.True);
330+
await OnIdleTestHelpers.AssertHandledAsync(psesHost, "$handledInProfile");
336331
}
337332
}
338333
}

0 commit comments

Comments
 (0)