Skip to content

Commit e1c019b

Browse files
fix(testing): skip unpack for local imports
The generated test images contain WASM content but declare no rootfs diff IDs. Running ctr's local unpack path is unnecessary and can leave snapshot cleanup racing later stress tests, causing intermittent "parent snapshot ... does not exist" failures. Keep legacy ctr imports unchanged while retaining --local for versions that require it. Signed-off-by: HarnageaGabriel <gabriel.harnagea06@gmail.com>
1 parent 120576d commit e1c019b

1 file changed

Lines changed: 43 additions & 9 deletions

File tree

crates/containerd-shim-wasm/src/testing.rs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,16 @@ pub mod oci_helpers {
370370
pub media_type: String,
371371
}
372372

373+
fn add_import_flags(command: &mut Command, use_local: bool) {
374+
if use_local {
375+
// The generated image config has no rootfs diff IDs, so these
376+
// tests only need the image and its content. Avoid creating local
377+
// snapshots whose asynchronous cleanup can race later tests.
378+
command.arg("--local").arg("--no-unpack");
379+
}
380+
command.arg("--all-platforms");
381+
}
382+
373383
pub fn import_image(
374384
image_name: &str,
375385
wasm_content: &[&ImageContent],
@@ -424,15 +434,8 @@ pub mod oci_helpers {
424434
.arg(TEST_NAMESPACE)
425435
.arg("image")
426436
.arg("import");
427-
if use_local {
428-
command.arg("--local");
429-
}
430-
let success = command
431-
.arg("--all-platforms")
432-
.arg(img_path)
433-
.spawn()?
434-
.wait()?
435-
.success();
437+
add_import_flags(&mut command, use_local);
438+
let success = command.arg(img_path).spawn()?.wait()?.success();
436439
if !success {
437440
// if the container still exists try cleaning it up
438441
bail!(" failed to import image");
@@ -611,4 +614,35 @@ pub mod oci_helpers {
611614

612615
Ok(())
613616
}
617+
618+
#[cfg(test)]
619+
mod tests {
620+
use super::*;
621+
622+
#[test]
623+
fn local_import_does_not_unpack() {
624+
let mut command = Command::new("ctr");
625+
626+
add_import_flags(&mut command, true);
627+
628+
let args: Vec<_> = command
629+
.get_args()
630+
.map(|arg| arg.to_str().unwrap())
631+
.collect();
632+
assert_eq!(args, ["--local", "--no-unpack", "--all-platforms"]);
633+
}
634+
635+
#[test]
636+
fn legacy_import_keeps_compatible_flags() {
637+
let mut command = Command::new("ctr");
638+
639+
add_import_flags(&mut command, false);
640+
641+
let args: Vec<_> = command
642+
.get_args()
643+
.map(|arg| arg.to_str().unwrap())
644+
.collect();
645+
assert_eq!(args, ["--all-platforms"]);
646+
}
647+
}
614648
}

0 commit comments

Comments
 (0)