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:
Dennis Kempin 2022-11-03 19:27:54 +00:00 committed by crosvm LUCI
parent e1a2b40496
commit 6027bee9ba
2 changed files with 27 additions and 9 deletions

View file

@ -285,6 +285,10 @@ impl CancellableBlockingPool {
/// thread will not complete and `await`ing on the `Task` for that work will panic.
///
pub fn shutdown(&self) -> Result<(), Error> {
self.shutdown_with_timeout(DEFAULT_SHUTDOWN_TIMEOUT)
}
fn shutdown_with_timeout(&self, timeout: Duration) -> Result<(), Error> {
self.disarm();
{
let mut state = self.inner.state.lock();
@ -297,9 +301,10 @@ impl CancellableBlockingPool {
state.wind_down = WindDownStates::ShuttingDown;
}
let res = self.inner.blocking_pool.shutdown(/* deadline: */ Some(
Instant::now() + DEFAULT_SHUTDOWN_TIMEOUT,
));
let res = self
.inner
.blocking_pool
.shutdown(/* deadline: */ Some(Instant::now() + timeout));
self.inner.state.lock().wind_down = WindDownStates::ShutDown;
match res {
@ -360,6 +365,8 @@ mod test {
use crate::blocking::Error;
use crate::CancellableBlockingPool;
const TEST_SHUTDOWN_TIMEOUT: Duration = Duration::from_millis(100);
#[test]
fn disarm_with_pending_work() {
// Create a pool with only one thread.
@ -403,7 +410,7 @@ mod test {
assert_eq!(block_on(unfinished), 0);
// Now the pool is empty and can be shutdown without blocking.
pool.shutdown().unwrap();
pool.shutdown_with_timeout(TEST_SHUTDOWN_TIMEOUT).unwrap();
}
#[test]
@ -427,14 +434,20 @@ mod test {
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]
fn multiple_shutdown_returns_error() {
let pool = CancellableBlockingPool::new(1, Duration::from_secs(10));
let _ = pool.shutdown();
assert_eq!(pool.shutdown(), Err(Error::AlreadyShutdown));
assert_eq!(
pool.shutdown_with_timeout(TEST_SHUTDOWN_TIMEOUT),
Err(Error::AlreadyShutdown)
);
}
#[test]
@ -461,8 +474,14 @@ mod test {
let pool_clone = pool.clone();
thread::spawn(move || {
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)
);
}
}

View file

@ -79,7 +79,6 @@ WIN64_DISABLED_CRATES = [
CRATE_OPTIONS: Dict[str, List[TestOption]] = {
"base": [TestOption.SINGLE_THREADED],
"cros_async": [TestOption.LARGE, TestOption.RUN_EXCLUSIVE],
"crosvm-fuzz": [TestOption.DO_NOT_BUILD], # b/194499769
"disk": [TestOption.DO_NOT_RUN_AARCH64, TestOption.DO_NOT_RUN_ARMHF], # b/202294155
"cros-fuzz": [TestOption.DO_NOT_BUILD],