-
-
Notifications
You must be signed in to change notification settings - Fork 3k
rt: make is_rt_shutdown_err method public #7771
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0ca69e7
rt: make is_rt_shutdown_err method public
Keruspe 1d32eab
Update tokio/src/runtime/runtime.rs
ADD-SP bd91e39
docs: improve is_rt_shutdown_err example and add tests
Darksonn afeee34
rt: try to make the CI pass
Keruspe e28e8ef
rt: actually fix panic=abort tests
Keruspe c5c180d
Merge branch 'master' into rt-shutdown-error
Darksonn 8475eb6
rt: disable rt_shutdown_err test on miri
Keruspe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #![warn(rust_2018_idioms)] | ||
| #![cfg(feature = "full")] | ||
| #![cfg(not(miri))] // No socket in miri. | ||
|
|
||
| use std::io; | ||
| use tokio::net::TcpListener; | ||
| use tokio::runtime::Builder; | ||
|
|
||
| fn rt() -> tokio::runtime::Runtime { | ||
| Builder::new_current_thread().enable_all().build().unwrap() | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_is_rt_shutdown_err() { | ||
| let rt1 = rt(); | ||
| let rt2 = rt(); | ||
|
|
||
| let listener = rt1.block_on(async { TcpListener::bind("127.0.0.1:0").await.unwrap() }); | ||
|
|
||
| drop(rt1); | ||
|
|
||
| rt2.block_on(async { | ||
| let res = listener.accept().await; | ||
| assert!(res.is_err()); | ||
| let err = res.as_ref().unwrap_err(); | ||
| assert!(tokio::runtime::is_rt_shutdown_err(err)); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_is_not_rt_shutdown_err() { | ||
| let err = io::Error::new(io::ErrorKind::Other, "some other error"); | ||
| assert!(!tokio::runtime::is_rt_shutdown_err(&err)); | ||
|
|
||
| let err = io::Error::new(io::ErrorKind::NotFound, "not found"); | ||
| assert!(!tokio::runtime::is_rt_shutdown_err(&err)); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg_attr(panic = "abort", ignore)] | ||
| fn test_join_error_panic() { | ||
| let rt = rt(); | ||
| let handle = rt.spawn(async { | ||
| panic!("oops"); | ||
| }); | ||
|
|
||
| let join_err = rt.block_on(handle).unwrap_err(); | ||
| let io_err: io::Error = join_err.into(); | ||
| assert!(!tokio::runtime::is_rt_shutdown_err(&io_err)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_join_error_cancelled() { | ||
| let rt = rt(); | ||
| let handle = rt.spawn(async { | ||
| std::future::pending::<()>().await; | ||
| }); | ||
| handle.abort(); | ||
| let join_err = rt.block_on(handle).unwrap_err(); | ||
| let io_err: io::Error = join_err.into(); | ||
| assert!(!tokio::runtime::is_rt_shutdown_err(&io_err)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_other_error_kinds_and_strings() { | ||
| // TimedOut | ||
| let err = io::Error::new(io::ErrorKind::TimedOut, "timed out"); | ||
| assert!(!tokio::runtime::is_rt_shutdown_err(&err)); | ||
|
|
||
| // Interrupted | ||
| let err = io::Error::from(io::ErrorKind::Interrupted); | ||
| assert!(!tokio::runtime::is_rt_shutdown_err(&err)); | ||
|
|
||
| // String that contains the shutdown message but has a prefix/suffix | ||
| let msg = "A Tokio 1.x context was found, but it is being shutdown. (extra info)"; | ||
| let err = io::Error::new(io::ErrorKind::Other, msg); | ||
| assert!(!tokio::runtime::is_rt_shutdown_err(&err)); | ||
|
|
||
| let msg = "Error: A Tokio 1.x context was found, but it is being shutdown."; | ||
| let err = io::Error::new(io::ErrorKind::Other, msg); | ||
| assert!(!tokio::runtime::is_rt_shutdown_err(&err)); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.