Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(EXC-1843): Make reservation test robust to costs #3539

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 200068382 bytes due to insufficient cycles.",
dsarlis marked this conversation as resolved.
Show resolved Hide resolved
);

// 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."
);
}
Loading