Fix bug of client_unread_response test

This commit is contained in:
Richard Chien 2021-01-27 12:04:23 +08:00
parent c201c15f8c
commit 99859d8019
1 changed files with 7 additions and 0 deletions

View File

@ -722,8 +722,12 @@ async fn test_client_cookie_handling() {
async fn client_unread_response() { async fn client_unread_response() {
let addr = test::unused_addr(); let addr = test::unused_addr();
let ready = Arc::new(std::sync::atomic::AtomicBool::new(false));
let ready_clone = ready.clone();
std::thread::spawn(move || { std::thread::spawn(move || {
let lst = std::net::TcpListener::bind(addr).unwrap(); let lst = std::net::TcpListener::bind(addr).unwrap();
ready_clone.store(true, Ordering::Relaxed);
for stream in lst.incoming() { for stream in lst.incoming() {
let mut stream = stream.unwrap(); let mut stream = stream.unwrap();
@ -738,6 +742,9 @@ async fn client_unread_response() {
} }
}); });
// wait for server thread ready
while !ready.load(Ordering::Relaxed) {}
// client request // client request
let req = awc::Client::new().get(format!("http://{}/", addr).as_str()); let req = awc::Client::new().get(format!("http://{}/", addr).as_str());
let mut res = req.send().await.unwrap(); let mut res = req.send().await.unwrap();