Skip to content

Commit

Permalink
agent: fix race condition when test watcher
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jongwu authored and bergwolf committed Nov 5, 2021
1 parent 0366f6e commit 06d3049
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/agent/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ scan_fmt = "0.2.3"
scopeguard = "1.0.0"
thiserror = "1.0.26"
regex = "1"
serial_test = "0.5.1"

# Async helpers
async-trait = "0.1.42"
Expand Down
12 changes: 12 additions & 0 deletions src/agent/src/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,10 @@ mod tests {
baremount.mount()
}

use serial_test::serial;

#[tokio::test]
#[serial]
async fn set_sandbox_storage() {
let logger = slog::Logger::root(slog::Discard, o!());
let mut s = Sandbox::new(&logger).unwrap();
Expand Down Expand Up @@ -500,6 +503,7 @@ mod tests {
}

#[tokio::test]
#[serial]
async fn remove_sandbox_storage() {
skip_if_not_root!();

Expand Down Expand Up @@ -556,6 +560,7 @@ mod tests {
}

#[tokio::test]
#[serial]
async fn unset_and_remove_sandbox_storage() {
skip_if_not_root!();

Expand Down Expand Up @@ -607,6 +612,7 @@ mod tests {
}

#[tokio::test]
#[serial]
async fn unset_sandbox_storage() {
let logger = slog::Logger::root(slog::Discard, o!());
let mut s = Sandbox::new(&logger).unwrap();
Expand Down Expand Up @@ -690,6 +696,7 @@ mod tests {
}

#[tokio::test]
#[serial]
async fn get_container_entry_exist() {
skip_if_not_root!();
let logger = slog::Logger::root(slog::Discard, o!());
Expand All @@ -703,6 +710,7 @@ mod tests {
}

#[tokio::test]
#[serial]
async fn get_container_no_entry() {
let logger = slog::Logger::root(slog::Discard, o!());
let mut s = Sandbox::new(&logger).unwrap();
Expand All @@ -712,6 +720,7 @@ mod tests {
}

#[tokio::test]
#[serial]
async fn add_and_get_container() {
skip_if_not_root!();
let logger = slog::Logger::root(slog::Discard, o!());
Expand All @@ -723,6 +732,7 @@ mod tests {
}

#[tokio::test]
#[serial]
async fn update_shared_pidns() {
skip_if_not_root!();
let logger = slog::Logger::root(slog::Discard, o!());
Expand All @@ -741,6 +751,7 @@ mod tests {
}

#[tokio::test]
#[serial]
async fn add_guest_hooks() {
let logger = slog::Logger::root(slog::Discard, o!());
let mut s = Sandbox::new(&logger).unwrap();
Expand All @@ -764,6 +775,7 @@ mod tests {
}

#[tokio::test]
#[serial]
async fn test_sandbox_set_destroy() {
let logger = slog::Logger::root(slog::Discard, o!());
let mut s = Sandbox::new(&logger).unwrap();
Expand Down
5 changes: 5 additions & 0 deletions src/agent/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,10 @@ mod tests {
);
}

use serial_test::serial;

#[tokio::test]
#[serial]
async fn create_tmpfs() {
skip_if_not_root!();

Expand All @@ -997,6 +1000,7 @@ mod tests {
}

#[tokio::test]
#[serial]
async fn spawn_thread() {
skip_if_not_root!();

Expand Down Expand Up @@ -1026,6 +1030,7 @@ mod tests {
}

#[tokio::test]
#[serial]
async fn verify_container_cleanup_watching() {
skip_if_not_root!();

Expand Down

0 comments on commit 06d3049

Please sign in to comment.