Fix HTML logger parallel file collision with atomic file creation#15562
Merged
nohwnd merged 1 commit intomicrosoft:mainfrom Mar 24, 2026
Merged
Fix HTML logger parallel file collision with atomic file creation#15562nohwnd merged 1 commit intomicrosoft:mainfrom
nohwnd merged 1 commit intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes cross-process collisions in the HTML logger’s output file creation by switching to OS-level atomic file creation and increasing timestamp granularity.
Changes:
- Use
FileMode.CreateNewinGenerateUniqueFilePathto avoid cross-process races. - Add fractional-second timestamps (
fffffff) to output naming for better uniqueness. - Add a unit test asserting the fractional-second filename pattern.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
test/Microsoft.TestPlatform.Extensions.HtmlLogger.UnitTests/HtmlLoggerTests.cs |
Adds coverage for the new fractional-second timestamp filename format. |
src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs |
Implements atomic file creation and updates timestamp formats used in generated filenames. |
test/Microsoft.TestPlatform.Extensions.HtmlLogger.UnitTests/HtmlLoggerTests.cs
Show resolved
Hide resolved
test/Microsoft.TestPlatform.Extensions.HtmlLogger.UnitTests/HtmlLoggerTests.cs
Show resolved
Hide resolved
test/Microsoft.TestPlatform.Extensions.HtmlLogger.UnitTests/HtmlLoggerTests.cs
Show resolved
Hide resolved
Replace lock-based file creation with atomic FileMode.CreateNew to prevent cross-process race conditions when multiple test processes generate HTML log files simultaneously. Changes: - Use FileMode.CreateNew instead of lock + File.Exists check in GenerateUniqueFilePath, making file creation atomic across processes - Add fractional seconds (fffffff) to timestamp format for better cross-process uniqueness in both FormatDateTimeForRunName and the LogFilePrefix path - Remove static FileCreateLockObject that only protected within a single process - Add test verifying fractional-seconds timestamp in generated filenames Fixes microsoft#15404 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Youssef1313
approved these changes
Mar 24, 2026
This was referenced Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix cross-process race condition in HTML logger file creation that causes collisions when multiple test processes run in parallel.
This is a cleaned-up version of #15435.
Changes
Closes #15404