From 9e802059f30d979eceb5922681ca3988ca75a235 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Thu, 11 Feb 2021 21:34:05 -0800 Subject: [PATCH] fix test and bench --- actix-http/src/config.rs | 5 +++-- benches/server.rs | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/actix-http/src/config.rs b/actix-http/src/config.rs index 719a04e18..f1007f923 100644 --- a/actix-http/src/config.rs +++ b/actix-http/src/config.rs @@ -323,13 +323,14 @@ mod tests { settings.set_date(&mut buf1); let now1 = settings.now(); - sleep_until(Instant::now() + Duration::from_secs(1)).await; + sleep_until(Instant::now() + Duration::from_secs(2)).await; + yield_now().await; let now2 = settings.now(); let mut buf2 = BytesMut::with_capacity(DATE_VALUE_LENGTH + 10); settings.set_date(&mut buf2); - assert!(now2 - now1 > Duration::from_millis(500)); + assert_ne!(now1, now2); assert_ne!(buf1, buf2); diff --git a/benches/server.rs b/benches/server.rs index 2471dd74c..9dd540a73 100644 --- a/benches/server.rs +++ b/benches/server.rs @@ -42,24 +42,25 @@ fn bench_async_burst(c: &mut Criterion) { c.bench_function("get_body_async_burst", move |b| { b.iter_custom(|iters| { - let client = - rt.block_on(async { Client::new().get(url.clone()).freeze().unwrap() }); + rt.block_on(async { + let client = Client::new().get(url.clone()).freeze().unwrap(); + + let start = std::time::Instant::now(); + // benchmark body - let start = std::time::Instant::now(); - // benchmark body - let resps = rt.block_on(async move { let burst = (0..iters).map(|_| client.send()); - join_all(burst).await - }); - let elapsed = start.elapsed(); + let resps = join_all(burst).await; - // if there are failed requests that might be an issue - let failed = resps.iter().filter(|r| r.is_err()).count(); - if failed > 0 { - eprintln!("failed {} requests (might be bench timeout)", failed); - }; + let elapsed = start.elapsed(); - elapsed + // if there are failed requests that might be an issue + let failed = resps.iter().filter(|r| r.is_err()).count(); + if failed > 0 { + eprintln!("failed {} requests (might be bench timeout)", failed); + }; + + elapsed + }) }) }); }