Skip to content

Commit fc97a40

Browse files
Assert OnIdle poll result with Assert.True
Follow-up to review feedback: the helper short-circuited with a bare `return` on success and only asserted (`Assert.Fail`) on timeout, so the happy path had no explicit assertion. Restructure the loop to poll until the handler variable is `$true` or the ~15s window elapses, then assert the outcome once with `Assert.True(handled, ...)`. Same behavior, but the success and timeout paths now share a single, self-describing assertion. Still green on net8.0. Drafted by Copilot (Claude Opus 4.8). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a3ba818 commit fc97a40

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +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), and fail if it never does within the timeout.
31+
// to drain the pending action), then assert it was set within the timeout.
3232
internal static async Task AssertHandledAsync(PsesInternalHost psesHost, string variableName)
3333
{
3434
using CancellationTokenSource cancellationSource = new(millisecondsDelay: 15000);
35-
while (!cancellationSource.IsCancellationRequested)
35+
bool handled = false;
36+
while (!handled && !cancellationSource.IsCancellationRequested)
3637
{
37-
IReadOnlyList<bool> handled = await psesHost.ExecutePSCommandAsync<bool>(
38+
IReadOnlyList<bool> result = await psesHost.ExecutePSCommandAsync<bool>(
3839
new PSCommand().AddScript(variableName),
3940
CancellationToken.None);
4041

41-
if (handled.Count > 0 && handled[0])
42+
handled = result.Count > 0 && result[0];
43+
if (!handled)
4244
{
43-
return;
45+
await Task.Delay(200);
4446
}
45-
46-
await Task.Delay(200);
4747
}
4848

49-
Assert.Fail($"Timed out waiting for the OnIdle handler to set '{variableName}'.");
49+
Assert.True(handled, $"Timed out waiting for the OnIdle handler to set '{variableName}'.");
5050
}
5151
}
5252

0 commit comments

Comments
 (0)