Skip to content

Commit

Permalink
enable custom section test with fewer loops
Browse files Browse the repository at this point in the history
  • Loading branch information
adambratschikaye committed Nov 21, 2024
1 parent b6915bf commit 16d392f
Showing 1 changed file with 68 additions and 68 deletions.
136 changes: 68 additions & 68 deletions rs/execution_environment/src/execution/install_code/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,74 +462,74 @@ fn install_code_succeeds_with_enough_wasm_custom_sections_memory() {
);
}

// #[test]
// fn install_code_respects_wasm_custom_sections_available_memory() {
// // As we install canisters in a loop, using more memory spawns thousands of
// // canister sandboxes, which lead to a few GiB memory usage.
// let available_wasm_custom_sections_memory = 20 * 1024; // 20KiB

// // This value might need adjustment if something changes in the canister's
// // wasm that gets installed in the test.
// let total_memory_taken_per_canister_in_bytes = 364249;

// let mut test = ExecutionTestBuilder::new()
// .with_install_code_instruction_limit(1_000_000_000)
// .with_install_code_slice_instruction_limit(1_000_000_000)
// .with_subnet_wasm_custom_sections_memory(available_wasm_custom_sections_memory)
// .with_manual_execution()
// .build();

// let subnet_available_memory_before = test.subnet_available_memory().get_execution_memory();
// let mut iterations = 0;
// loop {
// let canister_id = test
// .create_canister_with_allocation(Cycles::new(1_000_000_000_000_000), None, None)
// .unwrap();

// let payload = InstallCodeArgs {
// mode: CanisterInstallMode::Install,
// canister_id: canister_id.get(),
// wasm_module: include_bytes!("../../../tests/test-data/custom_sections.wasm").to_vec(),
// arg: vec![],
// compute_allocation: None,
// memory_allocation: None,
// sender_canister_version: None,
// };

// if test
// .subnet_message(Method::InstallCode, payload.encode())
// .is_err()
// {
// // We expect that at some point there is not enough wasm custom sections
// // memory left on the subnet and the request to install the canister
// // will fail.
// break;
// }
// iterations += 1;
// }

// // One more request to install a canister with wasm custom sections should fail.
// let canister_id = test
// .create_canister_with_allocation(Cycles::new(1_000_000_000_000_000), None, None)
// .unwrap();

// let payload = InstallCodeArgs {
// mode: CanisterInstallMode::Install,
// canister_id: canister_id.get(),
// wasm_module: include_bytes!("../../../tests/test-data/custom_sections.wasm").to_vec(),
// arg: vec![],
// compute_allocation: None,
// memory_allocation: None,
// sender_canister_version: None,
// };
// let result = test.subnet_message(Method::InstallCode, payload.encode());

// assert!(result.is_err());
// assert_eq!(
// test.subnet_available_memory().get_execution_memory(),
// subnet_available_memory_before - iterations * total_memory_taken_per_canister_in_bytes
// );
// }
#[test]
fn install_code_respects_wasm_custom_sections_available_memory() {
// Limit available custom section memory so that we can hit the limit with
// only a few canisters.
let available_wasm_custom_sections_memory = 1024; // 1 KiB

// This value might need adjustment if something changes in the canister's
// wasm that gets installed in the test.
let total_memory_taken_per_canister_in_bytes = 364249;

let mut test = ExecutionTestBuilder::new()
.with_install_code_instruction_limit(1_000_000_000)
.with_install_code_slice_instruction_limit(1_000_000_000)
.with_subnet_wasm_custom_sections_memory(available_wasm_custom_sections_memory)
.with_manual_execution()
.build();

let subnet_available_memory_before = test.subnet_available_memory().get_execution_memory();
let mut iterations = 0;
loop {
let canister_id = test
.create_canister_with_allocation(Cycles::new(1_000_000_000_000_000), None, None)
.unwrap();

let payload = InstallCodeArgs {
mode: CanisterInstallMode::Install,
canister_id: canister_id.get(),
wasm_module: include_bytes!("../../../tests/test-data/custom_sections.wasm").to_vec(),
arg: vec![],
compute_allocation: None,
memory_allocation: None,
sender_canister_version: None,
};

if test
.subnet_message(Method::InstallCode, payload.encode())
.is_err()
{
// We expect that at some point there is not enough wasm custom sections
// memory left on the subnet and the request to install the canister
// will fail.
break;
}
iterations += 1;
}

// One more request to install a canister with wasm custom sections should fail.
let canister_id = test
.create_canister_with_allocation(Cycles::new(1_000_000_000_000_000), None, None)
.unwrap();

let payload = InstallCodeArgs {
mode: CanisterInstallMode::Install,
canister_id: canister_id.get(),
wasm_module: include_bytes!("../../../tests/test-data/custom_sections.wasm").to_vec(),
arg: vec![],
compute_allocation: None,
memory_allocation: None,
sender_canister_version: None,
};
let result = test.subnet_message(Method::InstallCode, payload.encode());

assert!(result.is_err());
assert_eq!(
test.subnet_available_memory().get_execution_memory(),
subnet_available_memory_before - iterations * total_memory_taken_per_canister_in_bytes
);
}

fn execute_install_code_message_dts_helper(
test: &mut ExecutionTest,
Expand Down

0 comments on commit 16d392f

Please sign in to comment.