-
-
Notifications
You must be signed in to change notification settings - Fork 9
fix: parallel access to IFileStream
#799
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
When using parallel write to streams, in each stream only update the corresponding written bytes.
9a18f6a to
c27e6f4
Compare
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 enhances parallel write support for IFileStream by ensuring only the modified byte ranges are flushed per stream, and adds tests to validate this behavior.
- Added parallel write and flush behavior tests covering overlapping writes, differing lengths, and empty writes.
- Updated
FileStreamMockto track minimum and maximum write positions and flush only the modified segments. - Improved
TimerMockTestsby adding a null check before inspecting the exception message.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| Tests/Testably.Abstractions.Tests/FileSystem/FileStream/ParallelTests.cs | New tests verifying parallel write and flush behaviors under various scenarios. |
| Tests/Testably.Abstractions.Testing.Tests/TimeSystem/TimerMockTests.cs | Added an explicit null check for the exception message in the disposed timer test. |
| Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs | Introduced _minWrite/_maxWrite tracking, adjusted Write, WriteAsync, and flush logic to use these ranges. |
Comments suppressed due to low confidence (2)
Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs:180
- [nitpick] The fields
_minWriteand_maxWritecould be renamed to_minWritePositionand_maxWritePositionto more clearly convey that they represent stream positions.
private long _maxWrite;
Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs:607
- There are overrides for asynchronous writes that adjust
_minWrite/_maxWrite, but no tests appear to cover async write and flush behavior. Consider adding unit tests to ensure the range-flush logic works correctly forWriteAsync.
public override async Task WriteAsync(byte[] buffer, int offset, int count,
Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs
Outdated
Show resolved
Hide resolved
|
This PR should cover the cases mentioned in TestableIO/System.IO.Abstractions#1131. |
|
|
This is addressed in release v4.2.0. |

This PR enhances parallel write support for
IFileStreamby ensuring only the modified byte ranges are flushed per stream, and adds tests to validate this behavior.FileStreamMockto track minimum and maximum write positions and flush only the modified segments.