Skip to content

test: stabilise CI tests that fail under load or on Windows checkouts - #7882

Merged
thomhurst merged 1 commit into
mainfrom
fix/ci-flaky-tests
Nov 29, 2026
Merged

thomhurst merged 1 commit into
mainfrom
fix/ci-flaky-tests

Conversation

@thomhurst

@thomhurst thomhurst commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

I went through the failed runs of the .NET, AOT, Locale Test, Platform smoke tests and CloudShop Example Tests workflows since 2026-11-05: 271 failed .NET jobs and 187 failed jobs in the other workflows. Most failures were real breaks on a branch, such as Renovate major upgrades, runner image changes, or the PR's own changes. This PR fixes the failures that were caused by load, timing, or the checkout, not by a defect.

Failure Where Cause Fix
InstantiationTest*, 7 tests: VerifiedLineEndingException Every Windows workflow_dispatch and release run on main since 2026-11-14 (v1.88.0, v1.88.1). This one fails every time, it is not intermittent. Template snapshots are directories of .cs, .fs, .razor and other files. They checked out with CRLF, and Verify rejects a verified file that contains \r. .gitattributes: LF for tests/TUnit.Templates.Tests/Snapshots/**. Register .razor and .http as Verify text extensions, so the template sources (CRLF on Windows) are compared without line endings. All 12 template tests now pass locally on Windows; before, 7 failed.
Discovery_ReturnsFullTestCatalogue(net10.0): Timeout waiting for TCP connection after 60s macOS release runs v1.88.0 and v1.88.1 The runner was at 100% CPU. All retries of the dotnet run --no-build host failed to connect within 60 seconds. Start the built TUnit.TestProject.dll directly, without the MSBuild evaluation that dotnet run does first. Give connect and initialize a 3-minute budget. A host that exits early still fails at once.
RetainedLogs_FollowRuntimeInstance_AndSurviveDisposal, StartupDiagnostics_IncludeCrashedExecutableOutput: expected InvalidOperationException, got TimeoutException Ubuntu, 3 unrelated PRs ResourceTimeout was 60 seconds. Under load, DCP did not report the probe's crash in time. 5-minute ResourceTimeout. The fixture fails as soon as it sees the exit, so this only bounds a hang.
AbstractClassTests, AfterEveryAssemblyHookTests, AfterEveryClassHookTests, AfterTestAttributeTests: wrote no trx file ... Did it crash?, exit code 137 macOS Engine.Tests, 4 unrelated PRs Only the first child processes of the run (consecutive PIDs, the alphabetically first tests) got SIGKILL within 1 second, with no output. Later launches of the same executable ran normally. Relaunch a child (up to 3 attempts) only when it exited with 137, wrote no stdout, stderr or TRX, and the test does not act on the running process. Our own cancellation throws in CliWrap and does not report 137, so this cannot hide a cancellation test.
Apple smoke: CoreSimulatorService: Connection interrupted (exit 53), (ipc/mig) server died (exit 204) 3 unrelated PRs The hosted runner's simulator service dropped its connection during boot. Shut down, reboot and retry boot and install up to 3 times in Run-AppleSimulatorSmoke.sh.

AGENTS.md gets a new Writing resilient tests section: wait for events instead of time, no tight elapsed-time asserts, generous timeouts that only bound a hang, no dependence on order, culture, clock or line endings, isolated shared state, clear diagnostics for child processes, and [Retry] is not a fix.

Not changed

  • InstallPlaywrightModule (ETARGET playwright-core@1.65.0): on 2026-11-05 npm listed a version that the registry could not resolve yet. It happened on one day only.
  • Locale, AOT and Mocks AOT failures: all on Renovate major-upgrade branches (NU1202 and similar).
  • Apple MT7199 / Xcode 27.2 failures: runner image change on 2026-11-14, already fixed.

Test plan

  • TUnit.Templates.Tests on Windows: 12/12 pass (7 failed before, because of line endings)
  • TUnit.RpcTests: 14 passed, 2 skipped (by design), with the direct host launch
  • TUnit.Aspire.Tests CrashedExecutableLogTests: 2/2 pass
  • TUnit.Engine.Tests builds. I did not run it locally, as the repo guide says; CI covers it.
  • bash -n scripts/Run-AppleSimulatorSmoke.sh

Summary by CodeRabbit

  • Bug Fixes
    • Improved resilience when starting Apple simulators and test processes, including retries for certain startup failures.
    • Increased the time allowed for slow test-host and crash-reporting startup, reducing failures in slower environments.
  • Documentation
    • Added guidance for writing tests that remain reliable when CI runs slowly or in a different order.

- Template tests: check template snapshots out with LF and treat .razor and
  .http as text, so the Windows release and workflow_dispatch runs pass.
- RPC tests: start the built test host directly instead of through
  `dotnet run`, and give its connection and initialize steps three minutes.
- Aspire crash-probe tests: raise ResourceTimeout to five minutes. The
  fixture fails as soon as the probe exits, so this only bounds a hang.
- Engine tests: relaunch a child test application that macOS killed with
  SIGKILL before it wrote any output.
- Apple smoke: reboot the simulator and retry when CoreSimulatorService
  drops its connection during boot or install.
- AGENTS.md: add rules for writing tests that slow CI runners cannot break.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T14:01:29.170847Z a3d8489 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The pull request adds retry handling and longer startup timeouts to test workflows. It also updates template snapshot file handling and adds guidance for writing resilient tests.

Changes: Test Execution Resilience

Layer / File(s) Summary
Test resilience guidance and timeout
AGENTS.md, tests/TUnit.Aspire.Tests/CrashedExecutableLogTests.cs
The contributor guidance covers waits, timeouts, shared state, external failures, and test ordering. The crashing-probe fixture timeout increases from 60 seconds to five minutes.
Simulator boot and installation retry
scripts/Run-AppleSimulatorSmoke.sh
The script retries simulator boot-status checks and app installation up to three times. Failed attempts trigger a warning, a simulator shutdown attempt, and a 10-second delay.
Retry killed test processes
tests/TUnit.Engine.Tests/InvokableTestBase.cs
Test execution retries up to three launches when the process exits with code 137 before producing output or a TRX file. Retries are skipped when OnExecutingDelegates are configured.
RPC host launch and startup waits
tests/TUnit.RpcTests/TestProjectBuilds.cs, tests/TUnit.RpcTests/TestHostSession.cs
RPC tests resolve and launch the built host assembly directly. Connection acceptance and client initialization use a three-minute startup timeout.

Template Snapshot Handling

Layer / File(s) Summary
Snapshot line endings and text extensions
.gitattributes, tests/TUnit.Templates.Tests/GlobalSetup.cs
Snapshot files use LF line endings, and snapshot PNG files are marked binary. Template discovery registers .razor and .http as text extensions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Possibly related issues

  • TUnit issue 7607 — The retry targets the reported child-process exit with empty output and no TRX report, but does not address the issue’s root cause.

Possibly related PRs

  • thomhurst/TUnit#7810 — Both PRs address template snapshot line-ending handling and text-extension treatment.

Suggested reviewers: quattordici

Merge Risk: Minimal · up to a3d84

This change only affects test and CI infrastructure and contributor guidance. It makes tests more tolerant of slow CI runners and Windows line endings. No production behavior changes, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "test: stabilise CI tests that fail under load or on Windows checkouts" matches the main change. The PR stabilises CI tests across template snapshots (LF checkout and Verify text extensions …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "test: stabilise CI tests that fail under load or on Windows checkouts" matches the main change. The PR stabilises CI tests across template snapshots (LF checkout and Verify text extensions for Windows line endings), RPC host launch and longer startup timeouts, Aspire crash-probe timeout, Engine launch retries for exit code 137, and Apple simulator smoke retries. The title covers the load and Windows checkout themes stated in the objectives. It does not name each area, which the guidance allows.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the boot lights glow,
Then gives a quiet retry a go.
LF lines keep snapshots neat,
Long waits give tests room to complete.
I hop away as green checks grow.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3ebaad39-5b8c-4821-a01e-636d7f61447f
Commits

Reviewing files that changed from the base of the PR and between 01c0862 and a3d8489.

Files selected for processing: 8

  • .gitattributes
  • AGENTS.md
  • scripts/Run-AppleSimulatorSmoke.sh
  • tests/TUnit.Aspire.Tests/CrashedExecutableLogTests.cs
  • tests/TUnit.Engine.Tests/InvokableTestBase.cs
  • tests/TUnit.RpcTests/TestHostSession.cs
  • tests/TUnit.RpcTests/TestProjectBuilds.cs
  • tests/TUnit.Templates.Tests/GlobalSetup.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

Review

This PR fixes load- and checkout-related CI failures. The changes are well targeted, and each has a comment saying why it is there. I found no blocking issues.

What I checked

  • .gitattributes forces LF for the template snapshots and marks PNGs as binary. Registering .razor and .http as Verify text extensions is the right fix for the CRLF checkout.
  • The TestHostSession change starts the built DLL directly. HostAssemblyPath assumes the default bin/<Configuration>/<tfm>/ layout. I found no ArtifactsPath or OutputPath override in the repo props or the TestProject csproj, so it holds today. If the output layout changes, the failure will be a missing-file error from the host process. It would help to File.Exists-check the path and throw a clear message.
  • The 137 relaunch is tightly scoped: it needs exit code 137, empty stdout and stderr, no TRX, and no OnExecutingDelegates. This is reasonable, and the Console log line makes retries visible. One suggestion: a counter or summary of how often it fires would show whether the underlying macOS issue is getting worse. That is optional.
  • The simulator retry loop in Run-AppleSimulatorSmoke.sh is simple and correct. boot_and_install is called as a plain statement, so set -e still stops the script if it returns 1, assuming set -e is on.
  • The 5-minute ResourceTimeout and the 3-minute host startup budget only bound a hang, as the new AGENTS.md guidance says they should.

Minor point

  • The new "Writing resilient tests" section in AGENTS.md is useful. The [Retry] bullet and the new 137 relaunch are slightly in tension. The comments justify the relaunch as infrastructure noise outside our code, which matches the bullet's own exception, so I consider it consistent.

Overall this looks good to merge once CI is green.

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

This PR makes CI tests more tolerant of busy runners and Windows checkouts.

  • Template checks now compare snapshot files consistently on Windows.
  • RPC tests start their host directly and allow more startup time.
  • Crash-log tests wait longer for Aspire to report a failed probe.
  • Engine tests retry child processes killed before they write results.
  • Apple smoke runs retry simulator boot and app installation.
  • The repo guide now explains how to keep tests steady on slow runners.

No actionable issues were found. This review checked source code; it did not run tests.

Reviews (1) · Last reviewed commit: "test: stabilise CI tests that fail under..." · Reviewed by Greptile

@thomhurst
thomhurst enabled auto-merge (squash) November 29, 2026 14:08
@thomhurst
thomhurst merged commit 4f4b3a7 into main Nov 29, 2026
28 checks passed
@thomhurst
thomhurst deleted the fix/ci-flaky-tests branch November 29, 2026 14:23
This was referenced Dec 1, 2026

This branch was previously deployed

1 inactive deployment
Pull Requests — a3d8489c Deployed Nov 29, 2026 by thomhurst via modularpipeline (macos-latest) #21876
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.

1 participant