-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix flaky workloadIdentityCredentialIdentityBinding test on Windows #36745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Replace fs.unlink + fs.rmdir with fs.rm for reliable directory cleanup on Windows Co-authored-by: minhanh-phan <[email protected]>
There was a problem hiding this 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 fixes a Windows-specific flaky test failure in the @azure/identity package. The test should use custom token endpoint with CA file configuration was intermittently failing on Windows with ENOTEMPTY: directory not empty, rmdir errors during cleanup. The fix standardizes the directory cleanup approach to use the more robust fs.rm() method instead of the two-step fs.unlink() + fs.rmdir() pattern.
Key changes:
- Replaces two-step cleanup (
fs.unlink()+fs.rmdir()) with single-stepfs.rm()using recursive and force options - Applied to two test cases in the "Certificate Validation & Processing" section
|
Pipelines run success here |
sdk/identity/identity/test/internal/node/workloadIdentityCredentialIdentityBinding.spec.ts
Show resolved
Hide resolved
Move tempDir cleanup to afterEach to ensure cleanup happens even if assertions fail Co-authored-by: minhanh-phan <[email protected]>
Add try-catch to handle cleanup errors gracefully and reset variables to prevent stale path reuse Co-authored-by: minhanh-phan <[email protected]>
Change tempDir and tempCaFile to string | undefined for proper type safety Co-authored-by: minhanh-phan <[email protected]>
|
Pipelines succeed here |
|
/check-enforcer reset |
Packages impacted by this PR
Issues associated with this PR
Describe the problem that is addressed by this PR
Test
should use custom token endpoint with CA file configurationfails intermittently on Windows withENOTEMPTY: directory not empty, rmdir. The "Certificate Validation & Processing" tests usedfs.unlink()+fs.rmdir()for temp directory cleanup, which fails on Windows due to timing issues with file handle releases. Additionally, the inline cleanup approach meant that cleanup would not occur if test assertions failed.What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?
Two main approaches were implemented:
Replace two-step cleanup pattern: Changed from
fs.unlink()+fs.rmdir()tofs.rm(tempDir, { recursive: true, force: true })for reliable cross-platform directory cleanup. This pattern is already used elsewhere in this test file ("Configuration validation" and "Identity binding feature" sections).Refactor cleanup to afterEach block: Moved cleanup logic to an
afterEachhook to ensure cleanup happens even if test assertions fail. This involved:tempDirandtempCaFileas describe-block-level variables typed asstring | undefinedundefinedafter cleanup to prevent stale path reuseThis combined approach ensures both reliable cleanup on Windows and guaranteed cleanup regardless of test outcome.
Are there test cases added in this PR? (If not, why?)
No new tests needed—this fixes existing test cleanup reliability and robustness.
Provide a list of related PRs (if any)
N/A
Command used to generate this PR:**(Applicable only to SDK release request PRs)
N/A
Checklists
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.