Skip to content

Fix flaky testCopyFileReplacingExistingFileSucceeds#3554

Merged
fabianfett merged 4 commits intoapple:mainfrom
fabianfett:ff-fix-flaky-tests
Mar 18, 2026
Merged

Fix flaky testCopyFileReplacingExistingFileSucceeds#3554
fabianfett merged 4 commits intoapple:mainfrom
fabianfett:ff-fix-flaky-tests

Conversation

@fabianfett
Copy link
Copy Markdown
Member

Motivation

testCopyFileReplacingExistingFileSucceeds (and testCopySymlinkReplacingExistingSymlinkSucceeds) verify that no .tmp- prefixed files are left behind after a copyItem(replaceExisting: true) call on Linux. However, both tests create their files in the shared system temp directory (e.g. /tmp) and then scan that entire directory for .tmp- files. When other tests run in parallel, their in-flight copyItem(replaceExisting: true) operations leave transient .tmp- files in the same directory, causing spurious failures.

Changes

  • Both tests now create a dedicated subdirectory for their files, so the temp file scan only sees files belonging to that specific test.
  • Cleanup is handled via addTeardownBlock to ensure the subdirectory is removed even if the test fails early.

Results

The temp file assertions are no longer affected by concurrent test activity or other processes writing to the shared temp directory, eliminating the flakiness.

@fabianfett fabianfett requested a review from glbrntt March 18, 2026 14:34
@fabianfett
Copy link
Copy Markdown
Member Author

Sadly I wasn't able to reproduce the flaky tests on my machine. So this fix is a best guess.

@fabianfett fabianfett added the semver/none No version bump required. label Mar 18, 2026
@fabianfett fabianfett enabled auto-merge (squash) March 18, 2026 15:16
@fabianfett fabianfett merged commit 08abc3a into apple:main Mar 18, 2026
52 of 53 checks passed
@fabianfett fabianfett deleted the ff-fix-flaky-tests branch March 18, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/none No version bump required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants