Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshowers committed Nov 20, 2023
1 parent 302bf26 commit c2f11ed
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions tufaceous-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ serde_path_to_error.workspace = true
sha2.workspace = true
slog.workspace = true
tar.workspace = true
tokio.workspace = true
toml.workspace = true
tough.workspace = true
url = "2.4.1"
Expand Down
3 changes: 2 additions & 1 deletion tufaceous-lib/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ impl OmicronRepo {
let log = log.new(slog::o!("component" => "OmicronRepo"));
let repo_path = repo_path.canonicalize_utf8()?;
let root_json = repo_path.join("metadata").join("1.root.json");
let root = std::fs::read(&root_json)
let root = tokio::fs::read(&root_json)
.await
.with_context(|| format!("error reading from {root_json}"))?;

let repo = RepositoryLoader::new(
Expand Down
3 changes: 3 additions & 0 deletions wicketd/src/artifacts/artifacts_with_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ mod tests {

/// Test that `ArtifactsWithPlan` can extract the fake repository generated
/// by tufaceous.
///
/// See documentation for extract_nested_artifact_pair in update_plan.rs
/// for why multi_thread is required.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_extract_fake() -> Result<()> {
let logctx = test_setup_log("test_extract_fake");
Expand Down
12 changes: 7 additions & 5 deletions wicketd/src/artifacts/extracted_artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ use sha2::Digest;
use sha2::Sha256;
use slog::info;
use slog::Logger;
use std::fs::File;
use std::io;
use std::io::BufWriter;
use std::io::Write;
use std::sync::Arc;
use tokio::io::AsyncRead;
use tokio::io::AsyncWriteExt;
use tokio_util::io::ReaderStream;

/// Handle to the data of an extracted artifact.
Expand Down Expand Up @@ -124,7 +123,7 @@ impl ExtractedArtifacts {
self.tempdir.path().join(format!("{}", artifact_hash_id.hash))
}

/// Copy from `reader` into our temp directory, returning a handle to the
/// Copy from `stream` into our temp directory, returning a handle to the
/// extracted artifact on success.
pub(super) async fn store(
&mut self,
Expand All @@ -133,8 +132,9 @@ impl ExtractedArtifacts {
) -> Result<ExtractedArtifactDataHandle, RepositoryError> {
let output_path = self.path_for_artifact(&artifact_hash_id);

let mut writer = BufWriter::new(
File::create(&output_path)
let mut writer = tokio::io::BufWriter::new(
tokio::fs::File::create(&output_path)
.await
.with_context(|| {
format!("failed to create temp file {output_path}")
})
Expand All @@ -156,6 +156,7 @@ impl ExtractedArtifacts {
file_size += chunk.len();
writer
.write_all(&chunk)
.await
.with_context(|| format!("failed writing to {output_path}"))
.map_err(|error| RepositoryError::CopyExtractedArtifact {
kind: artifact_hash_id.kind.clone(),
Expand All @@ -165,6 +166,7 @@ impl ExtractedArtifacts {

writer
.flush()
.await
.with_context(|| format!("failed flushing {output_path}"))
.map_err(|error| RepositoryError::CopyExtractedArtifact {
kind: artifact_hash_id.kind.clone(),
Expand Down
2 changes: 2 additions & 0 deletions wicketd/src/artifacts/update_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,8 @@ mod tests {
builder.build_to_vec().unwrap()
}

// See documentation for extract_nested_artifact_pair for why multi_thread
// is required.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_update_plan_from_artifacts() {
const VERSION_0: SemverVersion = SemverVersion::new(0, 0, 0);
Expand Down
6 changes: 6 additions & 0 deletions wicketd/tests/integration_tests/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use wicketd_client::types::{
StartUpdateParams,
};

// See documentation for extract_nested_artifact_pair in update_plan.rs for why
// multi_thread is required.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_updates() {
let gateway = gateway_setup::test_setup("test_updates", SpPort::One).await;
Expand Down Expand Up @@ -258,6 +260,8 @@ async fn test_updates() {
wicketd_testctx.teardown().await;
}

// See documentation for extract_nested_artifact_pair in update_plan.rs for why
// multi_thread is required.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_installinator_fetch() {
let gateway = gateway_setup::test_setup("test_updates", SpPort::One).await;
Expand Down Expand Up @@ -391,6 +395,8 @@ async fn test_installinator_fetch() {
wicketd_testctx.teardown().await;
}

// See documentation for extract_nested_artifact_pair in update_plan.rs for why
// multi_thread is required.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_update_races() {
let gateway = gateway_setup::test_setup(
Expand Down

0 comments on commit c2f11ed

Please sign in to comment.