-
Notifications
You must be signed in to change notification settings - Fork 256
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
fix: MockFileInfo.Exists no longer returns stale cached data #828
Merged
Conversation
This file contains 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
In 5216e0d ("fix: make Mock{File,Directory}Info cache file attributes (TestableIO#791)", 2022-01-09) a cache of the MockFileData was introduced, to mimic the behaviour that a FileInfo object will not read the data from disk but instead also remembers its internal state, which can be updated by calling its `Refresh` method. This internal (or cached state) is invalidated when calling the methods `Create`, `Delete` and `MoveTo` methods, as can be seen by the `Invalidate` calls in https://github.com/dotnet/runtime/blob/8766a1cf1ed6c3b69cef50154139699b72fb52c5/src/libraries/System.Private.CoreLib/src/System/IO/FileInfo.cs In the PR TestableIO#791 it was overlooked to also invalidate the cached data in these methods. This commit fixes it by invalidating the cached data only for `Create`, `CreateText` and `Delete`. The two `MoveTo` variants are not changed as I could not manage to find any behaviour which is broken without that invalidation. Most likely reason is that the MockFileData is updated to represent the destination file ofter the move, so invalidating is not needed. Fixes TestableIO#822
Thanks a ton 👍 |
This was referenced Mar 23, 2022
This is addressed in release v16.1.24. |
This was referenced Mar 26, 2022
Update dependency System.IO.Abstractions to v16.1.25
TestableIO/System.IO.Abstractions.Analyzers#144
Merged
This same issue exists for |
rcdailey
added a commit
to rcdailey/System.IO.Abstractions
that referenced
this pull request
Jun 30, 2022
When invoking the `Create()` and `Delete()` methods on `MockDirectoryInfo`, the `Exists` property should intrinsically invoke `Refresh()` the next time it is called. This is necessary to prevent returning stale state about the directory after those operations. Additional test cases have been added for `MoveTo()` as well, to ensure it also not returning stale state. For context, this change was motivated by PR TestableIO#828 where similar issues were solved in `MockFileInfo`.
rcdailey
added a commit
to rcdailey/System.IO.Abstractions
that referenced
this pull request
Jul 11, 2022
When invoking the `Create()` and `Delete()` methods on `MockDirectoryInfo`, the `Exists` property should intrinsically invoke `Refresh()` the next time it is called. This is necessary to prevent returning stale state about the directory after those operations. Additional test cases have been added for `MoveTo()` as well, to ensure it also not returning stale state. For context, this change was motivated by PR TestableIO#828 where similar issues were solved in `MockFileInfo`.
mergify bot
pushed a commit
that referenced
this pull request
Jul 19, 2022
When invoking the `Create()` and `Delete()` methods on `MockDirectoryInfo`, the `Exists` property should intrinsically invoke `Refresh()` the next time it is called. This is necessary to prevent returning stale state about the directory after those operations. Additional test cases have been added for `MoveTo()` as well, to ensure it also not returning stale state. For context, this change was motivated by PR #828 where similar issues were solved in `MockFileInfo`. Co-authored-by: Florian Greinacher <florian@greinacher.de>
fgreinacher
added a commit
that referenced
this pull request
Jul 19, 2022
When invoking the `Create()` and `Delete()` methods on `MockDirectoryInfo`, the `Exists` property should intrinsically invoke `Refresh()` the next time it is called. This is necessary to prevent returning stale state about the directory after those operations. Additional test cases have been added for `MoveTo()` as well, to ensure it also not returning stale state. For context, this change was motivated by PR #828 where similar issues were solved in `MockFileInfo`. Co-authored-by: Florian Greinacher <florian@greinacher.de>
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.
In 5216e0d ("fix: make Mock{File,Directory}Info cache file attributes
(#791)", 2022-01-09) a cache of the MockFileData was introduced, to mimic
the behaviour that a FileInfo object will not read the data from disk
but instead also remembers its internal state, which can be updated by
calling its
Refresh
method. This internal (or cached state) isinvalidated when calling the methods
Create
,Delete
andMoveTo
methods, as can be seen by the
Invalidate
calls inhttps://github.com/dotnet/runtime/blob/8766a1cf1ed6c3b69cef50154139699b72fb52c5/src/libraries/System.Private.CoreLib/src/System/IO/FileInfo.cs
In the PR #791 it was overlooked to also invalidate the cached data
in these methods. This commit fixes it by invalidating the cached data
only for
Create
,CreateText
andDelete
.The two
MoveTo
variants are not changed as I could not manage to findany behaviour which is broken without that invalidation.
Most likely reason is that the MockFileData is updated to represent the
destination file ofter the move, so invalidating is not needed.
Fixes #822