Skip to content

Fix Windows CI: stop TestTempFile from deleting shared temp directory#1746

Merged
tonyqus merged 3 commits intonissl-lab:masterfrom
ken-swyfft:fix/ks/20260321_windows-ci-defender-exclusion
Mar 22, 2026
Merged

Fix Windows CI: stop TestTempFile from deleting shared temp directory#1746
tonyqus merged 3 commits intonissl-lab:masterfrom
ken-swyfft:fix/ks/20260321_windows-ci-defender-exclusion

Conversation

@ken-swyfft
Copy link
Contributor

@ken-swyfft ken-swyfft commented Mar 21, 2026

Summary

  • Root cause: TestTempFile.TestCreateTempFile() and TestGetTempFilePath() both call Directory.Delete(poifiles, true) in a retry loop, recursively deleting the shared %TEMP%\poifiles directory that ALL tests use for temp files
  • When dotnet test runs all test projects in parallel (3 projects × 2 frameworks = 6 concurrent processes), this nukes temp files that SXSSF and other tests are actively writing to
  • Fix: remove the destructive directory deletion; test directory recreation using an isolated subdirectory instead

Why different tests fail every run

The TestTempFile fixture runs in NPOI.TestCases.dll concurrently with NPOI.OOXML.TestCases.dll. Whichever OOXML test happens to be writing a temp file at the moment TestTempFile deletes the directory gets a random I/O error:

Symptom Cause
IOException: file being used by another process Directory.Delete conflicts with open file handles
FileNotFoundException Directory deleted while test tries to create/read a file
ZipException: EOF in header File partially written when directory was deleted
UnauthorizedAccessException Delete racing with create
NullReferenceException Cascade from failed I/O

Test plan

  • Verify Windows CI job passes with 0 test failures
  • Verify Ubuntu CI job continues to pass
  • Verify TestTempFile tests still pass (they do locally on both net8.0 and net472)

🤖 Generated with Claude Code

ken-swyfft and others added 3 commits March 21, 2026 14:53
Windows Defender real-time scanning on GitHub Actions runners grabs
newly created/modified files for inspection, causing intermittent
IOExceptions ("file being used by another process"), ZipExceptions
("EOF in header"), and FileNotFoundExceptions when tests try to
delete or reopen temp files during the scan window.

Exclude TEMP and workspace directories from Defender scanning in
both PR and CI workflows. This is standard practice for .NET OSS
projects running on Windows CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Path exclusions reduced failures from 6 to 2 but didn't fully
eliminate the race. Disable real-time monitoring instead, which
is the approach used by dotnet/runtime and other .NET OSS projects.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…tory

Root cause: TestTempFile.TestCreateTempFile() and TestGetTempFilePath()
both recursively delete the shared %TEMP%\poifiles directory to test
directory recreation. When dotnet test runs all test projects in
parallel, this nukes temp files that SXSSF tests and other tests are
actively using, causing random FileNotFoundException, IOException,
ZipException, and UnauthorizedAccessException failures.

Fix: Remove the destructive directory deletion from TestTempFile.
The directory recreation logic is now tested using an isolated
subdirectory that won't interfere with other parallel tests.

Also reverts the Defender exclusion changes from prior commits,
as Windows Defender was not the root cause.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ken-swyfft ken-swyfft changed the title Fix Windows CI failures: exclude paths from Defender scanning Fix Windows CI: stop TestTempFile from deleting shared temp directory Mar 21, 2026
@ken-swyfft ken-swyfft marked this pull request as ready for review March 21, 2026 22:37
@tonyqus tonyqus added this to the NPOI 2.8.0 milestone Mar 22, 2026
@tonyqus
Copy link
Member

tonyqus commented Mar 22, 2026

This issue blocked NPOI test for a long time. Thank you for fixing it!

@tonyqus tonyqus merged commit ab643f0 into nissl-lab:master Mar 22, 2026
3 checks passed
@tonyqus
Copy link
Member

tonyqus commented Mar 22, 2026

Unfortunately, there is still some random file occupation. But definitely, better than before
https://github.com/nissl-lab/npoi/actions/runs/23394322537/job/68054404003

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants