Skip to content

Commit

Permalink
Handle some race conditions in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vv9k committed Mar 31, 2023
1 parent dbfc654 commit 3ca9403
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
36 changes: 18 additions & 18 deletions tests/container_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,24 @@ async fn container_mount_unmount() {
let mount_path = mount_result.unwrap();
assert!(mount_path.exists());

let full_id = get_container_full_id(&podman, container_name).await;

let mut list_mounted_result = podman.containers().list_mounted().await;
if let Err(e) = list_mounted_result.as_ref() {
if e.to_string().contains("does not exist in database") {
// wait a bit in case a kill is executed at the same time
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
list_mounted_result = podman.containers().list_mounted().await;
}
}
println!("{list_mounted_result:?}");
assert!(list_mounted_result.is_ok());
let list_mounted_data = list_mounted_result.unwrap();
assert_eq!(
list_mounted_data.get(full_id).unwrap().as_str().unwrap(),
mount_path.to_string_lossy()
);

let unmount_result = container.unmount().await;
assert!(unmount_result.is_ok());
assert!(!mount_path.exists());
Expand Down Expand Up @@ -922,24 +940,6 @@ async fn containers_list() {
.unwrap()
.contains(&second_name.to_string()));

let container = podman.containers().get(container_name);
let _ = container.start(None).await;
let full_id = get_container_full_id(&podman, container_name).await;

let mount_result = container.mount().await;
assert!(mount_result.is_ok());
let mount_path = mount_result.unwrap();
assert!(mount_path.exists());

let list_mounted_result = podman.containers().list_mounted().await;
assert!(list_mounted_result.is_ok());
let list_mounted_data = list_mounted_result.unwrap();
assert_eq!(
list_mounted_data.get(full_id).unwrap().as_str().unwrap(),
mount_path.to_string_lossy()
);
container.unmount().await.unwrap();

cleanup_container(&podman, container_name).await;
cleanup_container(&podman, second_name).await;
}
Expand Down
9 changes: 8 additions & 1 deletion tests/image_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,14 @@ async fn image_list() {
.filter([filter])
.all(true)
.build();
let list_result = images.list(&list_opts).await;
let mut list_result = images.list(&list_opts).await;
if let Err(e) = list_result.as_ref() {
if e.to_string().contains("does not exist in database") {
// wait a bit in case a kill is executed at the same time
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
list_result = images.list(&list_opts).await;
}
}
assert!(list_result.is_ok());
let list_data = list_result.unwrap();
assert_eq!(list_data.len(), 2);
Expand Down

0 comments on commit 3ca9403

Please sign in to comment.