mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-10 12:09:31 +00:00
cros_async: Reduce timeout for CancellablePool in testing
The tests are explicitly verifying the timeout behavior, which by default is 5s. We can speed up the tests by using a smaller timeout when running a test. Reduces the time to run the test from 6s to 1s BUG=None TEST=tools/run_tests cros_async:cros_async -v Change-Id: I6262b653878171c6746a1ca90139b00a099dd91e Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4004299 Auto-Submit: Dennis Kempin <denniskempin@google.com> Reviewed-by: Vikram Auradkar <auradkar@google.com>
This commit is contained in:
parent
e1a2b40496
commit
6027bee9ba
2 changed files with 27 additions and 9 deletions
|
@ -285,6 +285,10 @@ impl CancellableBlockingPool {
|
||||||
/// thread will not complete and `await`ing on the `Task` for that work will panic.
|
/// thread will not complete and `await`ing on the `Task` for that work will panic.
|
||||||
///
|
///
|
||||||
pub fn shutdown(&self) -> Result<(), Error> {
|
pub fn shutdown(&self) -> Result<(), Error> {
|
||||||
|
self.shutdown_with_timeout(DEFAULT_SHUTDOWN_TIMEOUT)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shutdown_with_timeout(&self, timeout: Duration) -> Result<(), Error> {
|
||||||
self.disarm();
|
self.disarm();
|
||||||
{
|
{
|
||||||
let mut state = self.inner.state.lock();
|
let mut state = self.inner.state.lock();
|
||||||
|
@ -297,9 +301,10 @@ impl CancellableBlockingPool {
|
||||||
state.wind_down = WindDownStates::ShuttingDown;
|
state.wind_down = WindDownStates::ShuttingDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = self.inner.blocking_pool.shutdown(/* deadline: */ Some(
|
let res = self
|
||||||
Instant::now() + DEFAULT_SHUTDOWN_TIMEOUT,
|
.inner
|
||||||
));
|
.blocking_pool
|
||||||
|
.shutdown(/* deadline: */ Some(Instant::now() + timeout));
|
||||||
|
|
||||||
self.inner.state.lock().wind_down = WindDownStates::ShutDown;
|
self.inner.state.lock().wind_down = WindDownStates::ShutDown;
|
||||||
match res {
|
match res {
|
||||||
|
@ -360,6 +365,8 @@ mod test {
|
||||||
use crate::blocking::Error;
|
use crate::blocking::Error;
|
||||||
use crate::CancellableBlockingPool;
|
use crate::CancellableBlockingPool;
|
||||||
|
|
||||||
|
const TEST_SHUTDOWN_TIMEOUT: Duration = Duration::from_millis(100);
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn disarm_with_pending_work() {
|
fn disarm_with_pending_work() {
|
||||||
// Create a pool with only one thread.
|
// Create a pool with only one thread.
|
||||||
|
@ -403,7 +410,7 @@ mod test {
|
||||||
assert_eq!(block_on(unfinished), 0);
|
assert_eq!(block_on(unfinished), 0);
|
||||||
|
|
||||||
// Now the pool is empty and can be shutdown without blocking.
|
// Now the pool is empty and can be shutdown without blocking.
|
||||||
pool.shutdown().unwrap();
|
pool.shutdown_with_timeout(TEST_SHUTDOWN_TIMEOUT).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -427,14 +434,20 @@ mod test {
|
||||||
is_running = running.1.wait(is_running);
|
is_running = running.1.wait(is_running);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(pool.shutdown().err().unwrap(), Error::Timedout);
|
assert_eq!(
|
||||||
|
pool.shutdown_with_timeout(TEST_SHUTDOWN_TIMEOUT),
|
||||||
|
Err(Error::Timedout)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn multiple_shutdown_returns_error() {
|
fn multiple_shutdown_returns_error() {
|
||||||
let pool = CancellableBlockingPool::new(1, Duration::from_secs(10));
|
let pool = CancellableBlockingPool::new(1, Duration::from_secs(10));
|
||||||
let _ = pool.shutdown();
|
let _ = pool.shutdown();
|
||||||
assert_eq!(pool.shutdown(), Err(Error::AlreadyShutdown));
|
assert_eq!(
|
||||||
|
pool.shutdown_with_timeout(TEST_SHUTDOWN_TIMEOUT),
|
||||||
|
Err(Error::AlreadyShutdown)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -461,8 +474,14 @@ mod test {
|
||||||
let pool_clone = pool.clone();
|
let pool_clone = pool.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
while !pool_clone.inner.blocking_pool.shutting_down() {}
|
while !pool_clone.inner.blocking_pool.shutting_down() {}
|
||||||
assert_eq!(pool_clone.shutdown(), Err(Error::ShutdownInProgress));
|
assert_eq!(
|
||||||
|
pool_clone.shutdown_with_timeout(TEST_SHUTDOWN_TIMEOUT),
|
||||||
|
Err(Error::ShutdownInProgress)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
assert_eq!(pool.shutdown().err().unwrap(), Error::Timedout);
|
assert_eq!(
|
||||||
|
pool.shutdown_with_timeout(TEST_SHUTDOWN_TIMEOUT),
|
||||||
|
Err(Error::Timedout)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,6 @@ WIN64_DISABLED_CRATES = [
|
||||||
|
|
||||||
CRATE_OPTIONS: Dict[str, List[TestOption]] = {
|
CRATE_OPTIONS: Dict[str, List[TestOption]] = {
|
||||||
"base": [TestOption.SINGLE_THREADED],
|
"base": [TestOption.SINGLE_THREADED],
|
||||||
"cros_async": [TestOption.LARGE, TestOption.RUN_EXCLUSIVE],
|
|
||||||
"crosvm-fuzz": [TestOption.DO_NOT_BUILD], # b/194499769
|
"crosvm-fuzz": [TestOption.DO_NOT_BUILD], # b/194499769
|
||||||
"disk": [TestOption.DO_NOT_RUN_AARCH64, TestOption.DO_NOT_RUN_ARMHF], # b/202294155
|
"disk": [TestOption.DO_NOT_RUN_AARCH64, TestOption.DO_NOT_RUN_ARMHF], # b/202294155
|
||||||
"cros-fuzz": [TestOption.DO_NOT_BUILD],
|
"cros-fuzz": [TestOption.DO_NOT_BUILD],
|
||||||
|
|
Loading…
Reference in a new issue