Skip to content

Conversation

@vbreuss
Copy link
Member

@vbreuss vbreuss commented Jul 13, 2025

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 FileStreamMock to track minimum and maximum write positions and flush only the modified segments.

@vbreuss vbreuss self-assigned this Jul 13, 2025
@vbreuss vbreuss added the bug Something isn't working label Jul 13, 2025
When using parallel write to streams, in each stream only update the corresponding written bytes.
@vbreuss vbreuss force-pushed the topic/fix-parallel-stream-access branch from 9a18f6a to c27e6f4 Compare July 13, 2025 14:11
@vbreuss vbreuss requested a review from Copilot July 13, 2025 14:14
Copy link

Copilot AI left a 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 FileStreamMock to track minimum and maximum write positions and flush only the modified segments.
  • Improved TimerMockTests by 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 _minWrite and _maxWrite could be renamed to _minWritePosition and _maxWritePosition to 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 for WriteAsync.
	public override async Task WriteAsync(byte[] buffer, int offset, int count,

@vbreuss
Copy link
Member Author

vbreuss commented Jul 13, 2025

This PR should cover the cases mentioned in TestableIO/System.IO.Abstractions#1131.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 13, 2025

@vbreuss vbreuss enabled auto-merge (squash) July 13, 2025 14:43
@vbreuss vbreuss merged commit b755825 into main Jul 13, 2025
14 checks passed
@vbreuss vbreuss deleted the topic/fix-parallel-stream-access branch July 13, 2025 14:52
@github-actions
Copy link

Test Results

    37 files  ±  0      37 suites  ±0   15m 56s ⏱️ -7s
43 076 tests +163  40 697 ✅ +163  2 379 💤 ±0  0 ❌ ±0 
84 288 runs  +160  75 498 ✅ +160  8 790 💤 ±0  0 ❌ ±0 

Results for commit 9267997. ± Comparison against base commit 54775d4.

@github-actions
Copy link

This is addressed in release v4.2.0.

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

Labels

bug Something isn't working state: released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants