-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Reorganize tokio::fs::file's mock tests. #3988
Merged
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
The new organization changes the tests from integration tests into unit tests, and mocks std::fs::File with Mockall instead of custom logic. This approach has several advantages: * Does not require recompiling tokio::fs's source to build the integration tests * Does not mangle modules with #[path] * Does not interfere with adding more modules to fs (my main motivation) * Requires less custom code * Does not require renaming JoinHandle and spawn_blocking
Darksonn
reviewed
Jul 26, 2021
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.
Thanks, this seems like a good idea.
Darksonn
approved these changes
Jul 26, 2021
It seems like CI had a failure. |
Anything left to do, @Darksonn ? |
No, it seems good. Thanks for doing this! |
Thanks Darsonn. This will be necessary to have methods like File::write_at. |
hawkw
pushed a commit
that referenced
this pull request
Nov 16, 2021
hawkw
pushed a commit
that referenced
this pull request
Nov 16, 2021
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.
The new organization changes the tests from integration tests into unit
tests, and mocks std::fs::File with Mockall instead of custom logic.
This approach has several advantages:
integration tests
Motivation
The unusual design of tokio::fs's mock tests makes it very difficult to add additional submodules to tokio::fs. They would somehow have to be supplied by tokio/tests/fs_file_mocked.rs, and I couldn't figure out how to make it work.
Solution
Don't redefine src modules during the integration tests using
#[path]
. Instead, just run mock tests as unit tests, selectively using mock modules with#[cfg(test)]
. That's how most other Rust projects do it.