Skip to content

Commit

Permalink
nicer output for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Sep 2, 2024
1 parent 15d272f commit d3ae274
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions nexus/src/app/background/tasks/instance_reincarnation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@ mod test {
// Activate the task again, and check that our instance had an
// instance-start saga started.
let result = task.activate(&opctx).await;
assert_eq!(starter.count_reset(), 1);
let status =
serde_json::from_value::<InstanceReincarnationStatus>(result)
.expect("JSON must be correctly shaped");
eprintln!("activation: {status:#?}");

assert_eq!(starter.count_reset(), 1);
assert_eq!(status.instances_found, 1);
assert_eq!(
status.instances_reincarnated,
Expand Down Expand Up @@ -433,31 +435,34 @@ mod test {
}

// Activate the task again, and check that our instance had an
// instance-start saga started.
// instance-start saga started.
let result = task.activate(&opctx).await;
assert_eq!(starter.count_reset(), will_reincarnate.len() as u64);
let status =
serde_json::from_value::<InstanceReincarnationStatus>(result)
.expect("JSON must be correctly shaped");
eprintln!("activation: {status:#?}");

assert_eq!(starter.count_reset(), will_reincarnate.len() as u64);
assert_eq!(status.instances_found, will_reincarnate.len());
assert_eq!(status.already_reincarnated, Vec::new());
assert_eq!(status.query_error, None);
assert_eq!(status.restart_errors, Vec::new());

for id in &status.instances_reincarnated {
eprintln!("instance {id} reincarnated");
assert!(
will_reincarnate.contains(id),
"expected {id} to be reincarnated, but found {:?}",
!will_not_reincarnate.contains(id),
"expected {id} not to reincarnate! reincarnated: {:?}",
status.instances_reincarnated
);
}

for id in will_not_reincarnate {
for id in will_reincarnate {
assert!(
!status.instances_reincarnated.iter().any(|&i| i == id),
"expected {id} to not reincarnate, but found {:?}",
status.instances_reincarnated.contains(&id),
"expected {id} to have reincarnated! reincarnated: {:?}",
status.instances_reincarnated
);
)
}
}
}
2 changes: 1 addition & 1 deletion nexus/types/src/internal_api/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct RegionSnapshotReplacementFinishStatus {
}

/// The status of an `instance_reincarnation` background task activation.
#[derive(Default, Serialize, Deserialize)]
#[derive(Default, Serialize, Deserialize, Debug)]
pub struct InstanceReincarnationStatus {
/// Total number of instances in need of reincarnation on this activation.
pub instances_found: usize,
Expand Down

0 comments on commit d3ae274

Please sign in to comment.