Skip to content

Stabilize ToolTaskThatTimeoutAndRetry test#13489

Open
rainersigwald wants to merge 4 commits intomainfrom
tooltask-timeout-retry-test
Open

Stabilize ToolTaskThatTimeoutAndRetry test#13489
rainersigwald wants to merge 4 commits intomainfrom
tooltask-timeout-retry-test

Conversation

@rainersigwald
Copy link
Copy Markdown
Member

@rainersigwald rainersigwald commented Apr 6, 2026

  • Change fastDelayMilliseconds from NativeMethodsShared.IsWindows ? 1_000 : 100 to a flat 100
  • Verify test passes

rainersigwald and others added 2 commits April 6, 2026 11:29
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make the retry test assert the timeout scenario explicitly, log per-attempt diagnostics, and keep the follow-up executions deterministic across retries.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 6, 2026 16:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR stabilizes the ToolTaskThatTimeoutAndRetry unit test in Utilities.UnitTests by removing timing-sensitive shell indirection and making the timeout/retry expectations explicit and easier to diagnose when failures occur in CI.

Changes:

  • Replace the shell-based sleep invocation with direct OS tools (sleep on Unix, ping.exe on Windows) and document the timeout.exe limitation under ToolTask.
  • Refactor the theory inputs and assertions to explicitly model “first attempt times out, subsequent attempts succeed”.
  • Add per-attempt diagnostic output (including exit code) and clear the mock engine log between attempts to keep logs readable.

private sealed class ToolTaskThatSleeps : ToolTask
{
// Windows prompt command to sleep:
private readonly string _windowsSleep = "/c start /wait timeout {0}";
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This start /wait was (at least part of!) the reason running tests in our repo popped up terminal windows over and over. Not sure if that was bugging anybody else but it drove me up the wall!

Comment on lines +999 to +1001
/// These tests execute the same task instance multiple times using a direct OS sleep process rather than
/// shelling through PowerShell or cmd.exe. When configured to time out, the first execution is expected to
/// fail and all following executions must still succeed.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// These tests execute the same task instance multiple times using a direct OS sleep process rather than
/// shelling through PowerShell or cmd.exe. When configured to time out, the first execution is expected to
/// fail and all following executions must still succeed.
/// These tests execute the same task instance multiple times, which will in turn run a command to sleep for a
/// predefined amount of time. The first execution may time out, but all following ones won't. It is expected
/// that all following executions return success.```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied the suggested text in ac443a9.


int fastDelayMilliseconds = NativeMethodsShared.IsWindows ? 1_000 : 100;
int slowDelayMilliseconds = 5_000;
int timeoutMilliseconds = NativeMethodsShared.IsWindows ? 2_000 : 1_000;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot does this need to vary? Shouldn't it be irrelevant for the fast delay, and so could be 2s in both OS cases?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't need to vary. Removed the OS conditional — timeoutMilliseconds is now a flat 2_000 on all platforms (ac443a9). fastDelayMilliseconds is left as-is per the follow-up instruction.

protected override string GenerateCommandLineCommands() =>
NativeMethodsShared.IsUnixLike ?
string.Format(_unixSleep, RepeatCount < 2 ? InitialDelay / 1000.0 : FollowupDelay / 1000.0) :
string.Format(_windowsSleep, RepeatCount < 2 ? InitialDelay / 1000.0 : FollowupDelay / 1000.0);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hilariously, before this change we tried to timeout 0.001 and it worked only by

  • returning immediately
  • but we ignored the error code.

…onds

Agent-Logs-Url: https://github.com/dotnet/msbuild/sessions/766be90d-7dd3-492f-bb8d-4bf35765da5b

Co-authored-by: rainersigwald <3347530+rainersigwald@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/msbuild/sessions/81558234-b82a-4e91-8cbe-75dc53221865

Co-authored-by: rainersigwald <3347530+rainersigwald@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants