Skip to content

[tests] Fix flaky NSPasteboardTests.DetectMetadataTests on macOS - #25450

Merged
rolfbjarne merged 2 commits into
mainfrom
dev/rolf/issue-25446-nspasteboardtests
May 18, 2026
Merged

[tests] Fix flaky NSPasteboardTests.DetectMetadataTests on macOS#25450
rolfbjarne merged 2 commits into
mainfrom
dev/rolf/issue-25446-nspasteboardtests

Conversation

@rolfbjarne

@rolfbjarne rolfbjarne commented May 18, 2026

Copy link
Copy Markdown
Member

The DetectMetadata tests were flaky because the macOS pasteboard subsystem may not have fully analyzed content metadata by the time DetectMetadata is called immediately after SetStringForType. The callback would be invoked but return an empty dictionary.

Fix by:

  • Adding retry logic (up to 5 attempts with 500ms delays) for the '[appkit] Add NSImage lazy initialization #2' detection case where we expect results after writing content
  • Increasing WaitOne timeouts from 1s to 10s for CI under load

Fixes #25446

The DetectMetadata tests were flaky because the macOS pasteboard subsystem
may not have fully analyzed content metadata by the time DetectMetadata is
called immediately after SetStringForType. The callback would be invoked
but return an empty dictionary.

Fix by:
- Adding retry logic (up to 5 attempts with 500ms delays) for the '#2'
  detection case where we expect results after writing content
- Increasing WaitOne timeouts from 1s to 10s for CI under load

Fixes #25446

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 11:58

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.

Pull request overview

This PR addresses flakiness in the macOS NSPasteboard metadata detection tests by accommodating asynchronous pasteboard metadata analysis, which can return empty results immediately after writing content (as seen in issue #25446).

Changes:

  • Increased WaitOne timeouts for DetectMetadata callbacks from 1s to 10s to reduce CI timing sensitivity.
  • Added retry logic (up to 5 attempts with 500ms delays) for the “#2DetectMetadata case after writing a file URL to the pasteboard.
Comments suppressed due to low confidence (2)

tests/monotouch-test/AppKit/NSPasteboard.cs:434

  • The retry loop only checks detected.Count and doesn’t handle a non-null error per attempt. If an attempt returns an error, the loop may continue and overwrite it, potentially hiding a real problem. Suggest failing immediately (or at least asserting error is null) before deciding to retry.
				for (int attempt = 0; attempt < 5; attempt++) {
					evt.Reset ();
					detected = null;
					error = null;
					pasteboard.DetectMetadata (hashSet, callback);
					Assert.That (evt.WaitOne (TimeSpan.FromSeconds (10)), "SomewhatStronglyTyped DetectMetadata #2 wait");
					Assert.That (detected, Is.Not.Null, "SomewhatStronglyTyped DetectMetadata #2 patterns");
					if ((int) detected.Count > 0)
						break;
					Thread.Sleep (500);

tests/monotouch-test/AppKit/NSPasteboard.cs:498

  • The retry loop ignores error until after the loop, so an intermediate error can be overwritten by a later attempt and the test may pass unexpectedly. It would be safer to assert error is null on each attempt (and avoid retrying when an actual error is returned).
				for (int attempt = 0; attempt < 5; attempt++) {
					evt.Reset ();
					detected = null;
					error = null;
					pasteboard.DetectMetadata (hashSet, callback);
					Assert.That (evt.WaitOne (TimeSpan.FromSeconds (10)), "StronglyTyped DetectMetadata #2 wait");
					Assert.That (detected, Is.Not.Null, "StronglyTyped DetectMetadata #2 patterns");
					if ((int) detected.Count > 0)
						break;
					Thread.Sleep (500);

Comment thread tests/monotouch-test/AppKit/NSPasteboard.cs
Comment thread tests/monotouch-test/AppKit/NSPasteboard.cs
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@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

✅ [PR Build #54e7534] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 54e75347b257fd4f2bf58852a6c6e84a38e67344 [PR build]

@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: 54e75347b257fd4f2bf58852a6c6e84a38e67344 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #54e7534] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 54e75347b257fd4f2bf58852a6c6e84a38e67344 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #54e7534] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 54e75347b257fd4f2bf58852a6c6e84a38e67344 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
rolfbjarne enabled auto-merge (squash) May 18, 2026 16:25
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #54e7534] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 175 tests passed 🎉

Tests counts

✅ 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 Publish failed ⚠️) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. (⚠️ Html Report Publish failed ⚠️) Download
✅ framework: All 2 tests passed. (⚠️ Html Report Publish failed ⚠️) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. (⚠️ Html Report Publish failed ⚠️) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 16 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. (⚠️ Html Report Publish failed ⚠️) Download
✅ monotouch (macOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 16 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. [attempt 2] Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ 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: 54e75347b257fd4f2bf58852a6c6e84a38e67344 [PR build]

@rolfbjarne
rolfbjarne merged commit 3d65141 into main May 18, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI Postmortem] Flaky: NSPasteboardTests.DetectMetadataTests_SomewhatStronglyTyped on macOS

4 participants