Skip to content

Commit

Permalink
Speed up tests (#143)
Browse files Browse the repository at this point in the history
* Speed up tests by disabling retry logic

Mockito returns a 501 error, which the retry middleware interprets as a
transient failure, causing registry requests to retry unnecessarily
(with a delay)

* Add `process_rootfs_recipes` to return recipes used for setting up rootfs

* Split `bake_process` tests into separate tests again

* Update `bake_process` tests to save rootfs files across runs
  • Loading branch information
kylewlacy authored Dec 1, 2024
1 parent 0a797f6 commit 7261369
Show file tree
Hide file tree
Showing 7 changed files with 598 additions and 341 deletions.
101 changes: 101 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/brioche-core/src/bake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use super::{
Brioche,
};

pub use process::{process_rootfs_recipes, ProcessRootfsRecipes};

mod collect_references;
mod download;
mod process;
Expand Down
64 changes: 45 additions & 19 deletions crates/brioche-core/src/bake/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,14 @@ pub async fn bake_process(
// path is fully deterministic.
let guest_username = format!("brioche-runner-{hash}");
let guest_home_dir = format!("/home/{guest_username}");
set_up_rootfs(brioche, &root_dir, &guest_username, &guest_home_dir).await?;
set_up_rootfs(
brioche,
process.platform,
&root_dir,
&guest_username,
&guest_home_dir,
)
.await?;

let guest_home_dir = PathBuf::from(guest_home_dir);
let relative_home_dir = guest_home_dir
Expand Down Expand Up @@ -1188,6 +1195,7 @@ async fn append_dependency_envs(
#[tracing::instrument(skip(brioche))]
async fn set_up_rootfs(
brioche: &Brioche,
platform: crate::platform::Platform,
rootfs_dir: &Path,
guest_username: &str,
guest_home_dir: &str,
Expand All @@ -1200,28 +1208,16 @@ async fn set_up_rootfs(
link_locals: true,
};

let dash = Recipe::Unarchive(Unarchive {
archive: ArchiveFormat::Tar,
compression: CompressionFormat::Zstd,
file: Box::new(WithMeta::without_meta(Recipe::Download(DownloadRecipe {
url: "https://development-content.brioche.dev/github.com/tangramdotdev/bootstrap/2023-07-06/dash_amd64_linux.tar.zstd".parse()?,
hash: crate::Hash::Sha256 { value: hex::decode("ff52ae7e883ee4cbb0878f0e17decc18cd80b364147881fb576440e72e0129b2")? }
}))),
});
let env = Recipe::Unarchive(Unarchive {
archive: ArchiveFormat::Tar,
compression: CompressionFormat::Zstd,
file: Box::new(WithMeta::without_meta(Recipe::Download(DownloadRecipe {
url: "https://development-content.brioche.dev/github.com/tangramdotdev/bootstrap/2023-07-06/env_amd64_linux.tar.zstd".parse()?,
hash: crate::Hash::Sha256 { value: hex::decode("8f5b15a9b5c695663ca2caefa0077c3889fcf65793c9a20ceca4ab12c7007453")? }
}))),
});
let recipes = process_rootfs_recipes(platform);

tracing::debug!("resolving rootfs dash/env dependencies");
tracing::debug!("resolving rootfs sh/env dependencies");
let dash_and_env = super::bake(
brioche,
WithMeta::without_meta(Recipe::Merge {
directories: vec![WithMeta::without_meta(dash), WithMeta::without_meta(env)],
directories: vec![
WithMeta::without_meta(recipes.sh),
WithMeta::without_meta(recipes.env),
],
}),
&super::BakeScope::Anonymous,
)
Expand Down Expand Up @@ -1296,3 +1292,33 @@ impl Drop for BakeDir {
}
}
}

pub struct ProcessRootfsRecipes {
pub sh: Recipe,
pub env: Recipe,
}

pub fn process_rootfs_recipes(platform: crate::platform::Platform) -> ProcessRootfsRecipes {
match platform {
crate::platform::Platform::X86_64Linux => {
let sh = Recipe::Unarchive(Unarchive {
archive: ArchiveFormat::Tar,
compression: CompressionFormat::Zstd,
file: Box::new(WithMeta::without_meta(Recipe::Download(DownloadRecipe {
url: "https://development-content.brioche.dev/github.com/tangramdotdev/bootstrap/2023-07-06/dash_amd64_linux.tar.zstd".parse().unwrap(),
hash: crate::Hash::Sha256 { value: hex::decode("ff52ae7e883ee4cbb0878f0e17decc18cd80b364147881fb576440e72e0129b2").unwrap() }
}))),
});
let env = Recipe::Unarchive(Unarchive {
archive: ArchiveFormat::Tar,
compression: CompressionFormat::Zstd,
file: Box::new(WithMeta::without_meta(Recipe::Download(DownloadRecipe {
url: "https://development-content.brioche.dev/github.com/tangramdotdev/bootstrap/2023-07-06/env_amd64_linux.tar.zstd".parse().unwrap(),
hash: crate::Hash::Sha256 { value: hex::decode("8f5b15a9b5c695663ca2caefa0077c3889fcf65793c9a20ceca4ab12c7007453").unwrap() }
}))),
});

ProcessRootfsRecipes { sh, env }
}
}
}
8 changes: 8 additions & 0 deletions crates/brioche-core/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ impl RegistryClient {
.with(retry_middleware)
.build();

Self::new_with_client(client, url, auth)
}

pub fn new_with_client(
client: reqwest_middleware::ClientWithMiddleware,
url: url::Url,
auth: RegistryAuthentication,
) -> Self {
Self::Enabled { client, url, auth }
}

Expand Down
Loading

0 comments on commit 7261369

Please sign in to comment.