ci-test: ensure unique directory name for parallel testing
This commit is contained in:
@@ -4,6 +4,7 @@ use super::api::ContextDriver;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
pub struct LocalDriver;
|
pub struct LocalDriver;
|
||||||
|
|
||||||
@@ -20,8 +21,34 @@ impl ContextDriver for LocalDriver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_temp_dir(&self) -> io::Result<String> {
|
fn create_temp_dir(&self) -> io::Result<String> {
|
||||||
let temp_dir = tempfile::Builder::new().prefix("pkh-").tempdir()?;
|
// Generate a unique temporary directory name with random string
|
||||||
Ok(temp_dir.keep().to_string_lossy().to_string())
|
let base_timestamp = SystemTime::now()
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs();
|
||||||
|
|
||||||
|
let mut attempt = 0;
|
||||||
|
loop {
|
||||||
|
let work_dir_name = if attempt == 0 {
|
||||||
|
format!("pkh-{}", base_timestamp)
|
||||||
|
} else {
|
||||||
|
format!("pkh-{}-{}", base_timestamp, attempt)
|
||||||
|
};
|
||||||
|
|
||||||
|
let temp_dir_path = std::env::temp_dir().join(&work_dir_name);
|
||||||
|
|
||||||
|
// Check if directory already exists
|
||||||
|
if temp_dir_path.exists() {
|
||||||
|
attempt += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the directory
|
||||||
|
std::fs::create_dir_all(&temp_dir_path)?;
|
||||||
|
|
||||||
|
// Return the path as a string
|
||||||
|
return Ok(temp_dir_path.to_string_lossy().to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retrieve_path(&self, src: &Path, dest: &Path) -> io::Result<()> {
|
fn retrieve_path(&self, src: &Path, dest: &Path) -> io::Result<()> {
|
||||||
|
|||||||
@@ -112,17 +112,30 @@ impl ContextDriver for UnshareDriver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_temp_dir(&self) -> io::Result<String> {
|
fn create_temp_dir(&self) -> io::Result<String> {
|
||||||
// Create a temporary directory inside the chroot
|
// Create a temporary directory inside the chroot with unique naming
|
||||||
let timestamp = std::time::SystemTime::now()
|
let base_timestamp = std::time::SystemTime::now()
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_secs();
|
.as_secs();
|
||||||
|
|
||||||
let work_dir_name = format!("pkh-build-{}", timestamp);
|
let mut attempt = 0;
|
||||||
|
loop {
|
||||||
|
let work_dir_name = if attempt == 0 {
|
||||||
|
format!("pkh-build-{}", base_timestamp)
|
||||||
|
} else {
|
||||||
|
format!("pkh-build-{}-{}", base_timestamp, attempt)
|
||||||
|
};
|
||||||
|
|
||||||
let work_dir_inside_chroot = format!("/tmp/{}", work_dir_name);
|
let work_dir_inside_chroot = format!("/tmp/{}", work_dir_name);
|
||||||
|
let host_path = Path::new(&self.path).join("tmp").join(&work_dir_name);
|
||||||
|
|
||||||
|
// Check if directory already exists
|
||||||
|
if host_path.exists() {
|
||||||
|
attempt += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Create the directory on the host filesystem
|
// Create the directory on the host filesystem
|
||||||
let host_path = Path::new(&self.path).join("tmp").join(&work_dir_name);
|
|
||||||
std::fs::create_dir_all(&host_path)?;
|
std::fs::create_dir_all(&host_path)?;
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
@@ -132,7 +145,8 @@ impl ContextDriver for UnshareDriver {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Return the path as it appears inside the chroot
|
// Return the path as it appears inside the chroot
|
||||||
Ok(work_dir_inside_chroot)
|
return Ok(work_dir_inside_chroot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_path(&self, src: &Path, dest: &Path) -> io::Result<()> {
|
fn copy_path(&self, src: &Path, dest: &Path) -> io::Result<()> {
|
||||||
|
|||||||
@@ -159,11 +159,11 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[tokio::test]
|
#[tokio::test]
|
||||||
// #[test_log::test]
|
#[test_log::test]
|
||||||
// async fn test_deb_hello_ubuntu_end_to_end() {
|
async fn test_deb_hello_ubuntu_end_to_end() {
|
||||||
// test_build_end_to_end("hello", "noble", None, None, false).await;
|
test_build_end_to_end("hello", "noble", None, None, false).await;
|
||||||
// }
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[test_log::test]
|
#[test_log::test]
|
||||||
|
|||||||
Reference in New Issue
Block a user