fix test and bench

This commit is contained in:
fakeshadow 2021-02-11 21:34:05 -08:00
parent 438451edf2
commit 9e802059f3
2 changed files with 18 additions and 16 deletions

View File

@ -323,13 +323,14 @@ mod tests {
settings.set_date(&mut buf1); settings.set_date(&mut buf1);
let now1 = settings.now(); 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 now2 = settings.now();
let mut buf2 = BytesMut::with_capacity(DATE_VALUE_LENGTH + 10); let mut buf2 = BytesMut::with_capacity(DATE_VALUE_LENGTH + 10);
settings.set_date(&mut buf2); settings.set_date(&mut buf2);
assert!(now2 - now1 > Duration::from_millis(500)); assert_ne!(now1, now2);
assert_ne!(buf1, buf2); assert_ne!(buf1, buf2);

View File

@ -42,15 +42,15 @@ fn bench_async_burst(c: &mut Criterion) {
c.bench_function("get_body_async_burst", move |b| { c.bench_function("get_body_async_burst", move |b| {
b.iter_custom(|iters| { b.iter_custom(|iters| {
let client = rt.block_on(async {
rt.block_on(async { Client::new().get(url.clone()).freeze().unwrap() }); let client = Client::new().get(url.clone()).freeze().unwrap();
let start = std::time::Instant::now(); let start = std::time::Instant::now();
// benchmark body // benchmark body
let resps = rt.block_on(async move {
let burst = (0..iters).map(|_| client.send()); let burst = (0..iters).map(|_| client.send());
join_all(burst).await let resps = join_all(burst).await;
});
let elapsed = start.elapsed(); let elapsed = start.elapsed();
// if there are failed requests that might be an issue // if there are failed requests that might be an issue
@ -61,6 +61,7 @@ fn bench_async_burst(c: &mut Criterion) {
elapsed elapsed
}) })
})
}); });
} }