Skip to content

Commit

Permalink
fix(EXC-1843): Make reservation test robust to costs (#3539)
Browse files Browse the repository at this point in the history
EXC-1843

Adjust a test on reservation costs so that it doesn't rely on the exact
cycles costs because these might change.
  • Loading branch information
adambratschikaye authored Jan 22, 2025
1 parent 00f10af commit 7f9687b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions rs/execution_environment/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ DEV_DEPENDENCIES = [
"@crate_index//:libflate",
"@crate_index//:maplit",
"@crate_index//:proptest",
"@crate_index//:regex",
"@crate_index//:wasmparser",
"@crate_index//:wat",
]
Expand Down
1 change: 1 addition & 0 deletions rs/execution_environment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ itertools = { workspace = true }
libflate = { workspace = true }
maplit = "1.0.2"
proptest = { workspace = true }
regex = { workspace = true }
test-strategy = "0.3.1"
wasmparser = { workspace = true }
wat = { workspace = true }
Expand Down
41 changes: 25 additions & 16 deletions rs/execution_environment/tests/storage_reservation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,29 @@ fn test_storage_reservation_triggered_in_canister_snapshot_without_enough_cycles

// Take a snapshot to trigger more storage reservation. The canister does not have
// enough cycles in its balance, so this should fail.
let res = env.take_canister_snapshot(TakeCanisterSnapshotArgs::new(canister_id, None));
match res {
Ok(_) => panic!("Expected an error but got Ok(_)"),
Err(err) => {
assert_eq!(err.code(), ErrorCode::InsufficientCyclesInMemoryGrow);
// Match on a substring of the error message. Due to a difference in instructions consumed on
// Mac vs Linux, we cannot match on the exact number of cycles but we only need to verify it's
// a non-zero amount.
assert!(
err.description()
.contains("due to insufficient cycles. At least 339_559_"),
"Error message: {}",
err.description()
);
}
}
let err = env
.take_canister_snapshot(TakeCanisterSnapshotArgs::new(canister_id, None))
.expect_err("Expected an error, but got Ok(_)");
err.assert_contains(
ErrorCode::InsufficientCyclesInMemoryGrow,
"Canister cannot grow memory by",
);

// Match on a substring of the error message. Due to a difference in instructions consumed on
// Mac vs Linux, we cannot match on the exact number of cycles but we only need to verify it's
// a non-zero amount.
let regex = regex::Regex::new("At least ([0-9_]+) additional cycles are required.").unwrap();
let cycles_needed: u128 = regex
.captures(err.description())
.expect("Number regex match failed.")
.get(1)
.expect("No match for cycles needed.")
.as_str()
.replace("_", "")
.parse()
.expect("Failed to parse regex match for cycle count.");
assert!(
cycles_needed > 0,
"The amount of cycles needed is {cycles_needed} which is not positive."
);
}

0 comments on commit 7f9687b

Please sign in to comment.