Skip to content

Commit

Permalink
fix: Await all calls at once in xnet_test_canister
Browse files Browse the repository at this point in the history
When xnet_test_canister was migrated from dfn_core to ic_cdk, it retained the structure of the earlier, callback-based fanout() method. Which meant that it was now awaiting the calls to eacu subnet separately. In the xnet_slo_120_subnets_staging_test, this lead to extended ramp-up and and ranp-down periods, which caused the test to time out.

Instead, create futures for calls to all subnets first; and only then await them all.
  • Loading branch information
alin-at-dfinity authored and sasa-tomic committed Dec 6, 2024
1 parent 0dac15c commit d9fe207
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions rs/rust_canisters/xnet_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ async fn fanout() {
let network_topology =
NETWORK_TOPOLOGY.with(|network_topology| network_topology.borrow().clone());

let mut futures = vec![];
for canisters in network_topology {
if canisters.is_empty() {
continue;
Expand All @@ -182,7 +183,6 @@ async fn fanout() {
continue;
}

let mut futures = vec![];
for _ in 0..PER_SUBNET_RATE.with(|r| *r.borrow()) {
let idx = RNG.with(|rng| rng.borrow_mut().gen_range(0..canisters.len()));
let canister = canisters[idx];
Expand All @@ -200,30 +200,30 @@ async fn fanout() {
futures.push(res);
METRICS.with(move |m| m.borrow_mut().calls_attempted += 1);
}
}

let results = join_all(futures).await;
let results = join_all(futures).await;

for res in results {
match res {
Ok((reply,)) => {
let elapsed = Duration::from_nanos(time() - reply.time_nanos);
METRICS.with(|m| m.borrow_mut().latency_distribution.observe(elapsed));
}
Err((err_code, err_message)) => {
// Catch whether the call failed due to a synchronous or
// asynchronous error. Based on the current implementation of
// the Rust CDK, a synchronous error will contain a specific
// error message.
if err_message.contains("Couldn't send message") {
log(&format!(
"{} call failed with {:?}",
time() / 1_000_000,
err_code
));
METRICS.with(|m| m.borrow_mut().call_errors += 1);
} else {
METRICS.with(|m| m.borrow_mut().reject_responses += 1);
}
for res in results {
match res {
Ok((reply,)) => {
let elapsed = Duration::from_nanos(time() - reply.time_nanos);
METRICS.with(|m| m.borrow_mut().latency_distribution.observe(elapsed));
}
Err((err_code, err_message)) => {
// Catch whether the call failed due to a synchronous or
// asynchronous error. Based on the current implementation of
// the Rust CDK, a synchronous error will contain a specific
// error message.
if err_message.contains("Couldn't send message") {
log(&format!(
"{} call failed with {:?}",
time() / 1_000_000,
err_code
));
METRICS.with(|m| m.borrow_mut().call_errors += 1);
} else {
METRICS.with(|m| m.borrow_mut().reject_responses += 1);
}
}
}
Expand Down

0 comments on commit d9fe207

Please sign in to comment.