From 6027bee9ba964cfc44f18010c64f181c95e329a6 Mon Sep 17 00:00:00 2001 From: Dennis Kempin Date: Thu, 3 Nov 2022 19:27:54 +0000 Subject: [PATCH] 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 Reviewed-by: Vikram Auradkar --- cros_async/src/blocking/cancellable_pool.rs | 35 ++++++++++++++++----- tools/impl/test_config.py | 1 - 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/cros_async/src/blocking/cancellable_pool.rs b/cros_async/src/blocking/cancellable_pool.rs index 6659874c2d..89c2dc7bb5 100644 --- a/cros_async/src/blocking/cancellable_pool.rs +++ b/cros_async/src/blocking/cancellable_pool.rs @@ -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) + ); } } diff --git a/tools/impl/test_config.py b/tools/impl/test_config.py index 81619169d8..27f8a57a65 100755 --- a/tools/impl/test_config.py +++ b/tools/impl/test_config.py @@ -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],