agent: fix race condition when test watcher

create_tmpfs won't pass as the race condition in watcher umount. quote
James's words here:

1. Rust runs all tests in parallel.
2. Mounts are a process-wide, not a per-thread resource.
The only test that calls watcher.mount() is create_tmpfs().
However, other tests create BindWatcher objects.
3. BindWatcher's drop() implementation calls self.cleanup(),
which calls unmount for the mountpoint create_tmpfs() asserts.
4. The other tests are calling unmount whenever a BindWatcher goes
out of scope.

To avoid that issue, let the tests using BindWatcher in watcher and
sandbox.rs run sequentially.

Fixes: #2809
Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
This commit is contained in:
Jianyong Wu 2021-10-22 21:05:30 +08:00
parent 1a96b8ba35
commit 57c0f93f54
4 changed files with 19 additions and 0 deletions

1
src/agent/Cargo.lock generated
View File

@ -546,6 +546,7 @@ dependencies = [
"scopeguard", "scopeguard",
"serde", "serde",
"serde_json", "serde_json",
"serial_test",
"slog", "slog",
"slog-scope", "slog-scope",
"slog-stdlog", "slog-stdlog",

View File

@ -20,6 +20,7 @@ scan_fmt = "0.2.3"
scopeguard = "1.0.0" scopeguard = "1.0.0"
thiserror = "1.0.26" thiserror = "1.0.26"
regex = "1" regex = "1"
serial_test = "0.5.1"
# Async helpers # Async helpers
async-trait = "0.1.42" async-trait = "0.1.42"

View File

@ -464,7 +464,10 @@ mod tests {
baremount(src, dst, "bind", MsFlags::MS_BIND, "", logger) baremount(src, dst, "bind", MsFlags::MS_BIND, "", logger)
} }
use serial_test::serial;
#[tokio::test] #[tokio::test]
#[serial]
async fn set_sandbox_storage() { async fn set_sandbox_storage() {
let logger = slog::Logger::root(slog::Discard, o!()); let logger = slog::Logger::root(slog::Discard, o!());
let mut s = Sandbox::new(&logger).unwrap(); let mut s = Sandbox::new(&logger).unwrap();
@ -499,6 +502,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[serial]
async fn remove_sandbox_storage() { async fn remove_sandbox_storage() {
skip_if_not_root!(); skip_if_not_root!();
@ -555,6 +559,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[serial]
async fn unset_and_remove_sandbox_storage() { async fn unset_and_remove_sandbox_storage() {
skip_if_not_root!(); skip_if_not_root!();
@ -606,6 +611,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[serial]
async fn unset_sandbox_storage() { async fn unset_sandbox_storage() {
let logger = slog::Logger::root(slog::Discard, o!()); let logger = slog::Logger::root(slog::Discard, o!());
let mut s = Sandbox::new(&logger).unwrap(); let mut s = Sandbox::new(&logger).unwrap();
@ -689,6 +695,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[serial]
async fn get_container_entry_exist() { async fn get_container_entry_exist() {
skip_if_not_root!(); skip_if_not_root!();
let logger = slog::Logger::root(slog::Discard, o!()); let logger = slog::Logger::root(slog::Discard, o!());
@ -702,6 +709,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[serial]
async fn get_container_no_entry() { async fn get_container_no_entry() {
let logger = slog::Logger::root(slog::Discard, o!()); let logger = slog::Logger::root(slog::Discard, o!());
let mut s = Sandbox::new(&logger).unwrap(); let mut s = Sandbox::new(&logger).unwrap();
@ -711,6 +719,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[serial]
async fn add_and_get_container() { async fn add_and_get_container() {
skip_if_not_root!(); skip_if_not_root!();
let logger = slog::Logger::root(slog::Discard, o!()); let logger = slog::Logger::root(slog::Discard, o!());
@ -722,6 +731,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[serial]
async fn update_shared_pidns() { async fn update_shared_pidns() {
skip_if_not_root!(); skip_if_not_root!();
let logger = slog::Logger::root(slog::Discard, o!()); let logger = slog::Logger::root(slog::Discard, o!());
@ -740,6 +750,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[serial]
async fn add_guest_hooks() { async fn add_guest_hooks() {
let logger = slog::Logger::root(slog::Discard, o!()); let logger = slog::Logger::root(slog::Discard, o!());
let mut s = Sandbox::new(&logger).unwrap(); let mut s = Sandbox::new(&logger).unwrap();
@ -763,6 +774,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[serial]
async fn test_sandbox_set_destroy() { async fn test_sandbox_set_destroy() {
let logger = slog::Logger::root(slog::Discard, o!()); let logger = slog::Logger::root(slog::Discard, o!());
let mut s = Sandbox::new(&logger).unwrap(); let mut s = Sandbox::new(&logger).unwrap();

View File

@ -979,7 +979,10 @@ mod tests {
); );
} }
use serial_test::serial;
#[tokio::test] #[tokio::test]
#[serial]
async fn create_tmpfs() { async fn create_tmpfs() {
skip_if_not_root!(); skip_if_not_root!();
@ -994,6 +997,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[serial]
async fn spawn_thread() { async fn spawn_thread() {
skip_if_not_root!(); skip_if_not_root!();
@ -1023,6 +1027,7 @@ mod tests {
} }
#[tokio::test] #[tokio::test]
#[serial]
async fn verify_container_cleanup_watching() { async fn verify_container_cleanup_watching() {
skip_if_not_root!(); skip_if_not_root!();