let client = Client::builder().build::<_, crate::Body>(connector); let _ = client
.get("http://example.local/and/a/path".parse().unwrap())
.await
.expect_err("response should fail");
}
/* // FIXME: re-implement tests with `async/await` #[test] fnretryable_request(){ let_=pretty_env_logger::try_init();
letreq=Request::builder() .uri("http://mock.local/a") .body(Default::default()) .unwrap(); letres2=client.request(req); letmutsock1=Some(sock1); letsrv2=poll_fn(||{ // We purposefully keep the socket open until the client // has written the second request, and THEN disconnect. // // Not because we expect servers to be jerks, but to trigger // state where we write on an assumedly good connection, and // only reset the close AFTER we wrote bytes. try_ready!(sock1.as_mut().unwrap().read(&mut[0u8;512])); sock1.take(); Ok(Async::Ready(())) }).map_err(|e:std::io::Error|panic!("srv2poll_fnerror:{}",e)); leterr=rt.block_on(res2.join(srv2)).expect_err("res2"); assert!(err.is_incomplete_message(),"{:?}",err); }
// First request just sets us up to have a connection able to be put // back in the pool. *However*, it doesn't insert immediately. The // body has 1 pending byte, and we will only drain in request 2, once // the connect future has been started. letmutbody={ letres1=client.get(uri.clone()) .map(|res|res.into_body().concat2()); letsrv1=poll_fn(||{ try_ready!(sock1.read(&mut[0u8;512])); // Chunked is used so as to force 2 body reads. try_ready!(sock1.write(b"\ HTTP/1.1200OK\r\n\ transfer-encoding:chunked\r\n\ \r\n\ 1\r\nx\r\n\ 0\r\n\r\n\ ")); Ok(Async::Ready(())) }).map_err(|e:std::io::Error|panic!("srv1poll_fnerror:{}",e));
rt.block_on(res1.join(srv1)).expect("res1").0 };
// The second request triggers the only mocked connect future, but then // the drained body allows the first socket to go back to the pool, // "winning" the checkout race. { letres2=client.get(uri.clone()); letdrain=poll_fn(move||{ body.poll() }); letsrv2=poll_fn(||{ try_ready!(sock1.read(&mut[0u8;512])); try_ready!(sock1.write(b"HTTP/1.1200OK\r\nConnection:close\r\n\r\nx")); Ok(Async::Ready(())) }).map_err(|e:std::io::Error|panic!("srv2poll_fnerror:{}",e));
// "Release" the mocked connect future, and let the runtime spin once so // it's all setup... { letmuttx=Some(tx); letclient=&client; letkey=client.pool.h1_key("http://mock.local"); letmuttick_cnt=0; letfut=poll_fn(move||{ tx.take();
// Third request just tests out that the "loser" connection was pooled. If // it isn't, this will panic since the MockConnector doesn't have any more // mocks to give out. { letres3=client.get(uri); letsrv3=poll_fn(||{ try_ready!(sock2.read(&mut[0u8;512])); try_ready!(sock2.write(b"HTTP/1.1200OK\r\nContent-Length:0\r\n\r\n")); Ok(Async::Ready(())) }).map_err(|e:std::io::Error|panic!("srv3poll_fnerror:{}",e));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.