Skip to content

Commit

Permalink
Add some tests to show artifact type is plumbed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbobbio committed Jan 18, 2024
1 parent 7d2cf87 commit 86832b5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
23 changes: 16 additions & 7 deletions crates/maelstrom-broker/src/scheduler_task/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,29 +1061,38 @@ mod tests {
fixture.decrement_refcount(digest!(1), vec![Remove(long_path!("/z/sha256", 1, "tar"))]);
}

#[test]
fn got_artifact_already_in_cache() {
fn got_artifact_already_in_cache(ext: &str, type_: ArtifactType) {
let fs = TestCacheFs {
directories: HashMap::from([(
path_buf!("/z/sha256"),
vec![long_path!("/z/sha256", 1, "tar")],
vec![long_path!("/z/sha256", 1, ext)],
)]),
files: HashMap::from([(long_path!("/z/sha256", 1, "tar"), 1000)]),
files: HashMap::from([(long_path!("/z/sha256", 1, ext), 1000)]),
..Default::default()
};
let mut fixture = Fixture::new_and_clear_fs_operations(fs, 1000);
fixture.got_artifact(
ArtifactMetadata {
type_: ArtifactType::Tar,
type_,
digest: digest!(1),
size: 10,
},
short_path!("/z/tmp", 1, "tar"),
short_path!("/z/tmp", 1, ext),
vec![],
vec![Remove(short_path!("/z/tmp", 1, "tar"))],
vec![Remove(short_path!("/z/tmp", 1, ext))],
);
}

#[test]
fn got_artifact_already_in_cache_tar() {
got_artifact_already_in_cache("tar", ArtifactType::Tar);
}

#[test]
fn got_artifact_already_in_cache_manifest() {
got_artifact_already_in_cache("manifest", ArtifactType::Manifest);
}

#[test]
fn decrement_refcount_sets_priority_properly() {
let mut fixture = Fixture::new_and_clear_fs_operations(TestCacheFs::default(), 10);
Expand Down
26 changes: 25 additions & 1 deletion crates/maelstrom-broker/src/scheduler_task/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ mod tests {
}

script_test! {
get_artifact_for_worker,
get_artifact_for_worker_tar,
{
Fixture::new([], [], [
(
Expand All @@ -1571,6 +1571,30 @@ mod tests {
}
}

script_test! {
get_artifact_for_worker_manifest,
{
Fixture::new([], [], [
(
digest![42],
vec![Ok(("/a/good/path".into(), ArtifactMetadata {
type_: ArtifactType::Manifest,
digest: digest![42],
size: 42
}))]
),
])
},
GetArtifactForWorker(digest![42], worker_artifact_fetcher_sender![1]) => {
CacheGetArtifactForWorker(digest![42]),
ToWorkerArtifactFetcher(1, Ok(("/a/good/path".into(), ArtifactMetadata {
type_: ArtifactType::Manifest,
digest: digest![42],
size: 42
}))),
}
}

script_test! {
decrement_refcount,
DecrementRefcount(digest![42]) => {
Expand Down

0 comments on commit 86832b5

Please sign in to comment.