-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from adamreichold/read-timeout
Extend RequestBuilder to support specifying timeouts
- Loading branch information
Showing
4 changed files
with
83 additions
and
13 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::io; | ||
use std::net::TcpListener; | ||
use std::thread; | ||
use std::time::Duration; | ||
|
||
#[test] | ||
fn request_fails_due_to_read_timeout() { | ||
let listener = TcpListener::bind("localhost:0").unwrap(); | ||
let port = listener.local_addr().unwrap().port(); | ||
let thread = thread::spawn(move || { | ||
let _stream = listener.accept().unwrap(); | ||
thread::sleep(Duration::from_millis(500)); | ||
}); | ||
|
||
let result = attohttpc::get(format!("http://localhost:{}", port)) | ||
.read_timeout(Duration::from_millis(100)) | ||
.send(); | ||
|
||
match result { | ||
Err(err) => match err.kind() { | ||
attohttpc::ErrorKind::Io(err) => match err.kind() { | ||
io::ErrorKind::TimedOut | io::ErrorKind::WouldBlock => (), | ||
err => panic!("Unexpected I/O error: {:?}", err), | ||
}, | ||
err => panic!("Unexpected error: {:?}", err), | ||
}, | ||
Ok(resp) => panic!("Unexpected response: {:?}", resp), | ||
} | ||
|
||
thread.join().unwrap(); | ||
} |