mirror of https://github.com/fafhrd91/actix-web
fix slow request test
This commit is contained in:
parent
b7e3cdff2e
commit
d78108bbec
|
@ -195,6 +195,7 @@ impl TimerState {
|
|||
};
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn reset(&mut self, deadline: Instant, line: u32) {
|
||||
if !self.is_enabled() {
|
||||
log::warn!("resetting disabled timer from line {}", line);
|
||||
|
@ -999,7 +1000,8 @@ where
|
|||
);
|
||||
debug_assert!(
|
||||
this.state.is_none(),
|
||||
"dispatcher should not be in keep-alive phase if state is not none",
|
||||
"dispatcher should not be in keep-alive phase if state is not none: {:?}",
|
||||
this.state,
|
||||
);
|
||||
debug_assert!(
|
||||
this.write_buf.is_empty(),
|
||||
|
@ -1134,6 +1136,8 @@ where
|
|||
Poll::Ready(Ok(n)) => {
|
||||
log::trace!(" read {} bytes", n);
|
||||
|
||||
this.flags.remove(Flags::FINISHED);
|
||||
|
||||
if n == 0 {
|
||||
log::trace!(" signalling should_disconnect");
|
||||
return Ok(true);
|
||||
|
@ -1141,10 +1145,12 @@ where
|
|||
|
||||
read_some = true;
|
||||
}
|
||||
|
||||
Poll::Pending => {
|
||||
log::trace!(" read pending");
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
Poll::Ready(Err(err)) => {
|
||||
log::trace!(" read err: {:?}", &err);
|
||||
|
||||
|
@ -1259,7 +1265,7 @@ where
|
|||
PollResponse::DrainWriteBuf => true,
|
||||
|
||||
PollResponse::DoNothing => {
|
||||
if inner.flags.contains(Flags::KEEP_ALIVE) {
|
||||
if inner.flags.contains(Flags::FINISHED | Flags::KEEP_ALIVE) {
|
||||
if let Some(deadline) = inner.config.keep_alive_timer() {
|
||||
log::trace!("setting keep-alive timer");
|
||||
inner.as_mut().project().ka_timer.set_and_init(
|
||||
|
|
|
@ -198,8 +198,6 @@ async fn test_chunked_payload() {
|
|||
|
||||
#[actix_rt::test]
|
||||
async fn slow_request_close() {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
let mut srv = test_server(|| {
|
||||
HttpService::build()
|
||||
.client_timeout(200)
|
||||
|
@ -213,18 +211,21 @@ async fn slow_request_close() {
|
|||
|
||||
let mut stream = net::TcpStream::connect(srv.addr()).unwrap();
|
||||
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
|
||||
let mut data = Vec::new();
|
||||
let _ = stream.read(&mut data).unwrap();
|
||||
let mut data = String::new();
|
||||
let _ = stream.read_to_string(&mut data).unwrap();
|
||||
assert!(
|
||||
data.is_empty(),
|
||||
"connection should close without writing a response"
|
||||
data.starts_with("HTTP/1.1 408 Request Timeout"),
|
||||
"response was not 408: {}",
|
||||
data
|
||||
);
|
||||
|
||||
let end = Instant::now();
|
||||
let diff = Instant::now().duration_since(start);
|
||||
|
||||
if end.duration_since(start) > Duration::from_secs(1) {
|
||||
if diff < Duration::from_secs(1) {
|
||||
// test success
|
||||
} else if diff < Duration::from_secs(3) {
|
||||
panic!("request seems to have wrongly timed-out according to keep-alive");
|
||||
} else {
|
||||
panic!("request took way too long to time out");
|
||||
}
|
||||
|
||||
|
@ -232,7 +233,7 @@ async fn slow_request_close() {
|
|||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_slow_request_408() {
|
||||
async fn slow_request_408() {
|
||||
let mut srv = test_server(|| {
|
||||
HttpService::build()
|
||||
.client_timeout(200)
|
||||
|
@ -245,7 +246,7 @@ async fn test_slow_request_408() {
|
|||
let start = Instant::now();
|
||||
|
||||
let mut stream = net::TcpStream::connect(srv.addr()).unwrap();
|
||||
let _ = stream.write_all(b"GET /test/tests/test HTTP/1.1\r\n");
|
||||
let _ = stream.write_all(b"GET /test HTTP/1.1\r\n");
|
||||
let mut data = String::new();
|
||||
let _ = stream.read_to_string(&mut data);
|
||||
assert!(
|
||||
|
@ -254,8 +255,7 @@ async fn test_slow_request_408() {
|
|||
data
|
||||
);
|
||||
|
||||
let end = Instant::now();
|
||||
let diff = end - start;
|
||||
let diff = Instant::now().duration_since(start);
|
||||
|
||||
if diff < Duration::from_secs(1) {
|
||||
// test success
|
||||
|
|
Loading…
Reference in New Issue