mirror of https://github.com/zkat/cacache-rs.git
tests: stop spawning a new tokio runtime every benchmark iteration
This commit is contained in:
parent
526386ada8
commit
7afcb8d649
|
|
@ -37,6 +37,7 @@ walkdir = "2.3.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.4.0"
|
criterion = "0.4.0"
|
||||||
|
lazy_static = "1.4.0"
|
||||||
tokio = { version = "1.12.0", features = [
|
tokio = { version = "1.12.0", features = [
|
||||||
"fs",
|
"fs",
|
||||||
"io-util",
|
"io-util",
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,19 @@ use tokio::fs as afs;
|
||||||
|
|
||||||
#[cfg(all(test, feature = "async-std"))]
|
#[cfg(all(test, feature = "async-std"))]
|
||||||
pub use async_std::task::block_on;
|
pub use async_std::task::block_on;
|
||||||
|
|
||||||
|
#[cfg(all(test, feature = "tokio"))]
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
static ref TOKIO_RUNTIME: tokio::runtime::Runtime = tokio::runtime::Runtime::new().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(test, feature = "tokio"))]
|
#[cfg(all(test, feature = "tokio"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn block_on<F, T>(future: F) -> T
|
pub fn block_on<F, T>(future: F) -> T
|
||||||
where
|
where
|
||||||
F: std::future::Future<Output = T>,
|
F: std::future::Future<Output = T>,
|
||||||
{
|
{
|
||||||
tokio::runtime::Runtime::new().unwrap().block_on(future)
|
TOKIO_RUNTIME.block_on(future)
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue