From 9101bb10468b4c4e9c94609383693b2fedcb96be Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 2 Feb 2024 15:45:12 +0100 Subject: [PATCH] only build image once per test runner run --- src/container.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/container.rs b/src/container.rs index dbdfc0b8..08c7c988 100644 --- a/src/container.rs +++ b/src/container.rs @@ -2,8 +2,8 @@ use std::fs; use std::path::Path; use std::process::{self, Child, Output}; use std::process::{Command, Stdio}; -use std::sync::atomic; use std::sync::atomic::AtomicUsize; +use std::sync::{atomic, Once}; use tempfile::NamedTempFile; @@ -17,6 +17,7 @@ pub struct Container { impl Container { /// Starts the container in a "parked" state pub fn run() -> Result { + static ONCE: Once = Once::new(); static COUNT: AtomicUsize = AtomicUsize::new(0); // TODO configurable: hickory; bind @@ -37,11 +38,11 @@ impl Container { .arg("-f") .arg(dockerfile_path) .arg(docker_dir_path); - let status = command.status()?; - if !status.success() { - return Err(format!("`{command:?}` failed").into()); - } + ONCE.call_once(|| { + let status = command.status().unwrap(); + assert!(status.success()); + }); let mut command = Command::new("docker"); let pid = process::id();