-
-
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
net: add track_caller to public APIs #4805
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3eb71f2
net: add track_caller to public APIs
hds 62a7455
Added track_caller to max_instances
hds 0918514
sync: add track_caller to public APIs
hds dedc60e
Modified changes to some panic descriptions
hds 990fb3a
Updated panic description
hds 73c5aea
Only test udp_socket_from_std_panic_caller when not on easi
hds 9ff7e4d
Merge branch 'master', remote-tracking branch 'origin' into track-cal…
hds 373c17a
Ignore all net_panic tests when target is wasi
hds 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 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 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 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 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 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 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 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 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 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 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,188 @@ | ||
#![warn(rust_2018_idioms)] | ||
#![cfg(feature = "full")] | ||
|
||
use std::error::Error; | ||
use tokio::net::{TcpListener, TcpStream}; | ||
use tokio::runtime::{Builder, Runtime}; | ||
|
||
mod support { | ||
pub mod panic; | ||
} | ||
use support::panic::test_panic; | ||
|
||
#[test] | ||
fn udp_socket_from_std_panic_caller() -> Result<(), Box<dyn Error>> { | ||
hds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use std::net::SocketAddr; | ||
use tokio::net::UdpSocket; | ||
|
||
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap(); | ||
let std_sock = std::net::UdpSocket::bind(addr).unwrap(); | ||
std_sock.set_nonblocking(true).unwrap(); | ||
|
||
let panic_location_file = test_panic(|| { | ||
let rt = runtime_without_io(); | ||
rt.block_on(async { | ||
let _sock = UdpSocket::from_std(std_sock); | ||
}); | ||
}); | ||
|
||
// The panic location should be in this file | ||
assert_eq!(&panic_location_file.unwrap(), file!()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn tcp_listener_from_std_panic_caller() -> Result<(), Box<dyn Error>> { | ||
let std_listener = std::net::TcpListener::bind("127.0.0.1:8080").unwrap(); | ||
std_listener.set_nonblocking(true).unwrap(); | ||
|
||
let panic_location_file = test_panic(|| { | ||
let rt = runtime_without_io(); | ||
rt.block_on(async { | ||
let _ = TcpListener::from_std(std_listener); | ||
}); | ||
}); | ||
|
||
// The panic location should be in this file | ||
assert_eq!(&panic_location_file.unwrap(), file!()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn tcp_stream_from_std_panic_caller() -> Result<(), Box<dyn Error>> { | ||
let std_listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); | ||
|
||
let std_stream = std::net::TcpStream::connect(std_listener.local_addr().unwrap()).unwrap(); | ||
std_stream.set_nonblocking(true).unwrap(); | ||
|
||
let panic_location_file = test_panic(|| { | ||
let rt = runtime_without_io(); | ||
rt.block_on(async { | ||
let _ = TcpStream::from_std(std_stream); | ||
}); | ||
}); | ||
|
||
// The panic location should be in this file | ||
assert_eq!(&panic_location_file.unwrap(), file!()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(unix)] | ||
fn unix_listener_bind_panic_caller() -> Result<(), Box<dyn Error>> { | ||
use tokio::net::UnixListener; | ||
|
||
let dir = tempfile::tempdir().unwrap(); | ||
let sock_path = dir.path().join("socket"); | ||
|
||
let panic_location_file = test_panic(|| { | ||
let rt = runtime_without_io(); | ||
rt.block_on(async { | ||
let _ = UnixListener::bind(&sock_path); | ||
}); | ||
}); | ||
|
||
// The panic location should be in this file | ||
assert_eq!(&panic_location_file.unwrap(), file!()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(unix)] | ||
fn unix_listener_from_std_panic_caller() -> Result<(), Box<dyn Error>> { | ||
use tokio::net::UnixListener; | ||
|
||
let dir = tempfile::tempdir().unwrap(); | ||
let sock_path = dir.path().join("socket"); | ||
let std_listener = std::os::unix::net::UnixListener::bind(&sock_path).unwrap(); | ||
|
||
let panic_location_file = test_panic(|| { | ||
let rt = runtime_without_io(); | ||
rt.block_on(async { | ||
let _ = UnixListener::from_std(std_listener); | ||
}); | ||
}); | ||
|
||
// The panic location should be in this file | ||
assert_eq!(&panic_location_file.unwrap(), file!()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(unix)] | ||
fn unix_stream_from_std_panic_caller() -> Result<(), Box<dyn Error>> { | ||
use tokio::net::UnixStream; | ||
|
||
let dir = tempfile::tempdir().unwrap(); | ||
let sock_path = dir.path().join("socket"); | ||
let _std_listener = std::os::unix::net::UnixListener::bind(&sock_path).unwrap(); | ||
let std_stream = std::os::unix::net::UnixStream::connect(&sock_path).unwrap(); | ||
|
||
let panic_location_file = test_panic(|| { | ||
let rt = runtime_without_io(); | ||
rt.block_on(async { | ||
let _ = UnixStream::from_std(std_stream); | ||
}); | ||
}); | ||
|
||
// The panic location should be in this file | ||
assert_eq!(&panic_location_file.unwrap(), file!()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(unix)] | ||
fn unix_datagram_from_std_panic_caller() -> Result<(), Box<dyn Error>> { | ||
use std::os::unix::net::UnixDatagram as StdUDS; | ||
use tokio::net::UnixDatagram; | ||
|
||
let dir = tempfile::tempdir().unwrap(); | ||
let sock_path = dir.path().join("socket"); | ||
|
||
// Bind the socket to a filesystem path | ||
// /let socket_path = tmp.path().join("socket"); | ||
let std_socket = StdUDS::bind(&sock_path).unwrap(); | ||
std_socket.set_nonblocking(true).unwrap(); | ||
|
||
let panic_location_file = test_panic(move || { | ||
let rt = runtime_without_io(); | ||
rt.block_on(async { | ||
let _ = UnixDatagram::from_std(std_socket); | ||
}); | ||
}); | ||
|
||
// The panic location should be in this file | ||
assert_eq!(&panic_location_file.unwrap(), file!()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(windows)] | ||
fn server_options_max_instances_panic_caller() -> Result<(), Box<dyn Error>> { | ||
use tokio::net::windows::named_pipe::ServerOptions; | ||
|
||
let panic_location_file = test_panic(move || { | ||
let rt = runtime_without_io(); | ||
rt.block_on(async { | ||
let mut options = ServerOptions::new(); | ||
options.max_instances(255); | ||
}); | ||
}); | ||
|
||
// The panic location should be in this file | ||
assert_eq!(&panic_location_file.unwrap(), file!()); | ||
|
||
Ok(()) | ||
} | ||
|
||
// Runtime without `enable_io` so it has no IO driver set. | ||
fn runtime_without_io() -> Runtime { | ||
Builder::new_current_thread().build().unwrap() | ||
} |
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.
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.
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.
@hds Did you have any thoughts on this doc change?
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.
@Darksonn I agree with them, it fits in with the rest of the docs. I'll make them in all the relevant spots in the next few days - I've been on holiday and have extended that to not opening my computer at all for a week. (-;
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.
Alright. The next release is probably a month from now, so there's no rush.
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.
Fixed.