Skip to content

[tests] Fix CreateAndBuildProjectTemplate hang/flakiness for Mac Catalyst - #26564

Merged
rolfbjarne merged 4 commits into
mainfrom
dev/rolf/tests-ignore-more-saved-state
Sep 7, 2026
Merged

[tests] Fix CreateAndBuildProjectTemplate hang/flakiness for Mac Catalyst#26564
rolfbjarne merged 4 commits into
mainfrom
dev/rolf/tests-ignore-more-saved-state

Conversation

@rolfbjarne

@rolfbjarne rolfbjarne commented Sep 4, 2026

Copy link
Copy Markdown
Member

Two issues in the 'Execute'/'DeleteSavedState' helpers used by the Mac Catalyst 'CreateAndBuildProjectTemplate' tests could cause the test process to hang for 30 seconds (or longer) waiting on an unattended 'Do you want to try to reopen its windows again?' AppKit modal dialog:

  • 'DeleteSavedState' only deleted '.savedState', but macOS stores Mac Catalyst apps' saved state under '~iosmac.savedState' (the 'iosmac' personality suffix), so the saved state was never actually being cleaned up.

  • Even with a clean Saved Application State folder, AppKit also tracks a separate persistent 'crash history' per bundle identifier that isn't stored in that folder and isn't cleared by deleting it. After many crashed/killed test runs sharing the same default bundle identifier, this alone could still trigger the modal.

Fix both: delete the '~iosmac' saved-state variant too, and set the application default 'ApplePersistenceIgnoreState' to 'YES', which tells AppKit to skip the restore-prompt flow entirely regardless of any tracked crash history.

Copilot-Session: 0d41380a-e6ee-470e-b837-68411050a4f6

…lyst

Two issues in the 'Execute'/'DeleteSavedState' helpers used by the
Mac Catalyst 'CreateAndBuildProjectTemplate' tests could cause the test
process to hang for 30 seconds (or longer) waiting on an unattended
'Do you want to try to reopen its windows again?' AppKit modal dialog:

 * 'DeleteSavedState' only deleted '<bundleid>.savedState', but macOS
   stores Mac Catalyst apps' saved state under
   '<bundleid>~iosmac.savedState' (the 'iosmac' personality suffix), so
   the saved state was never actually being cleaned up.

 * Even with a clean Saved Application State folder, AppKit also
   tracks a separate persistent 'crash history' per bundle identifier
   that isn't stored in that folder and isn't cleared by deleting it.
   After many crashed/killed test runs sharing the same default bundle
   identifier, this alone could still trigger the modal.

Fix both: delete the '~iosmac' saved-state variant too, and launch the
test app with '-ApplePersistenceIgnoreState YES', which tells AppKit to
skip the restore-prompt flow entirely regardless of any tracked crash
history.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d41380a-e6ee-470e-b837-68411050a4f6
Copilot AI lite review requested due to automatic review settings September 4, 2026 13:41

Copilot AI left a comment

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.

🟡 Changes recommended

The new launch argv modifies args.Length, and many test apps return args.Length as their exit code, which will turn previously-successful runs into failures.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR targets flakiness/hangs in the Mac Catalyst CreateAndBuildProjectTemplate-style execution helpers by preventing macOS/AppKit state-restore prompts from blocking unattended test runs.

Changes:

  • Launches the built app with -ApplePersistenceIgnoreState YES to bypass AppKit’s “reopen windows” restore prompt flow.
  • Improves saved-state cleanup by also deleting the ~iosmac.savedState variant used by Mac Catalyst apps.
File summaries
File Description
tests/dotnet/UnitTests/TestBaseClass.cs Adjusts app execution arguments to avoid AppKit restore prompts and expands saved-state deletion to include the ~iosmac personality suffix.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread tests/dotnet/UnitTests/TestBaseClass.cs Outdated
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 2 commits September 7, 2026 13:22
Use the defaults command to configure ApplePersistenceIgnoreState for the test app, then remove the override after execution. Keep the app launch argument list empty so tests that use args.Length as their exit code continue to pass.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

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.

🟡 Changes recommended

The new defaults write/delete is redundantly executed twice per run (inside a loop) and the implementation diverges from the PR description, both of which should be resolved to avoid introducing new flakiness and confusion.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

tests/dotnet/UnitTests/TestBaseClass.cs:536

  • ⚠️ defaults write/delete is executed inside the foreach loop, so it runs twice (once per identifier variant) with identical arguments. This adds unnecessary process launches and can extend timeouts (each call allows 30s), increasing test runtime/flakiness. Move the defaults call outside the loop (and consider logging failures via ExitCode/output for the write case).
					if (cleanup) {
						Execution.RunAsync ("/usr/bin/defaults", new [] { "delete", bundleIdentifier, "ApplePersistenceIgnoreState" }, timeout: TimeSpan.FromSeconds (30)).Result;
					} else {
						Execution.RunAsync ("/usr/bin/defaults", new [] { "write", bundleIdentifier, "ApplePersistenceIgnoreState", "-bool", "YES" }, timeout: TimeSpan.FromSeconds (30)).Result;
					}
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread tests/dotnet/UnitTests/TestBaseClass.cs
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: edd4d3ea320f93012c13d512f0d528e2521e8027 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #edd4d3e] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 264 tests passed 🎉

Tests counts

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 7 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 31 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 25 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: edd4d3ea320f93012c13d512f0d528e2521e8027 [PR build]

@rolfbjarne
rolfbjarne enabled auto-merge (squash) September 7, 2026 17:39
@rolfbjarne rolfbjarne added the ready-to-review This PR is ready to review/merge. label Sep 7, 2026
@rolfbjarne
rolfbjarne merged commit 659b158 into main Sep 7, 2026
54 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/tests-ignore-more-saved-state branch September 7, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot ready-to-review This PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants