Skip to content

Commit

Permalink
Bind to localhost in client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reu committed Aug 24, 2024
1 parent d7021c8 commit d8a7c80
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ mod tests {

#[test]
fn test_client() {
let listener = TcpListener::bind("0.0.0.0:0").unwrap();
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let port = listener.local_addr().unwrap().port();

thread::spawn(move || {
Expand All @@ -164,7 +164,7 @@ mod tests {
});

let mut client = Client::new();
let uri = format!("http://localhost:{port}");
let uri = format!("http://127.0.0.1:{port}");

let res = client
.request(
Expand All @@ -191,7 +191,7 @@ mod tests {

#[test]
fn send_request() {
let listener = TcpListener::bind("0.0.0.0:0").unwrap();
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let port = listener.local_addr().unwrap().port();

thread::spawn(move || {
Expand All @@ -200,7 +200,7 @@ mod tests {
.ok()
});

let conn = TcpStream::connect(("0.0.0.0", port)).unwrap();
let conn = TcpStream::connect(("127.0.0.1", port)).unwrap();

let req = http::Request::builder().body("Hello world").unwrap();
let (conn, res) = send(conn, req).unwrap();
Expand All @@ -224,7 +224,7 @@ mod tests {

#[test]
fn correctly_handles_closing_connections() {
let listener = TcpListener::bind("0.0.0.0:0").unwrap();
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let port = listener.local_addr().unwrap().port();

thread::spawn(move || {
Expand All @@ -237,7 +237,7 @@ mod tests {
.ok();
});

let conn = TcpStream::connect(("0.0.0.0", port)).unwrap();
let conn = TcpStream::connect(("127.0.0.1", port)).unwrap();

let req = http::Request::builder().body(()).unwrap();
let (conn, res) = send(conn, req).unwrap();
Expand All @@ -248,7 +248,7 @@ mod tests {

#[test]
fn keep_http_10_connection_alive_when_asked_to() {
let listener = TcpListener::bind("0.0.0.0:0").unwrap();
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let port = listener.local_addr().unwrap().port();

thread::spawn(move || {
Expand All @@ -257,7 +257,7 @@ mod tests {
.ok();
});

let conn = TcpStream::connect(("0.0.0.0", port)).unwrap();
let conn = TcpStream::connect(("127.0.0.1", port)).unwrap();

let req = http::Request::builder()
.version(Version::HTTP_10)
Expand Down

0 comments on commit d8a7c80

Please sign in to comment.