Skip to content

Commit a786cd1

Browse files
committed
Extract load test round logic into run_round function and use it once
or in a loop depending on --endless, instead of a loop-with-break pattern.
1 parent ab55110 commit a786cd1

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

tooling/load_test/src/main.rs

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,11 @@ async fn load_test(
273273

274274
/// Waits until the confirmed nonce of each account reaches its target.
275275
async fn wait_until_all_included(
276-
client: EthClient,
276+
client: &EthClient,
277277
timeout: Option<Duration>,
278278
targets: Vec<(Address, u64)>,
279279
) -> Result<(), String> {
280280
for (src, target_nonce) in targets {
281-
let client = client.clone();
282281
let encoded_src: String = src.encode_hex();
283282
let mut last_updated = tokio::time::Instant::now();
284283
let mut last_nonce = 0;
@@ -398,38 +397,47 @@ async fn main() {
398397
None
399398
};
400399

401-
let mut round = 1;
402-
loop {
403-
println!(
404-
"Starting load test round {round} with {} transactions per account...",
405-
cli.tx_amount
406-
);
407-
let time_now = tokio::time::Instant::now();
408-
409-
let targets = load_test(
410-
cli.tx_amount,
411-
accounts.clone(),
412-
client.clone(),
413-
chain_id,
414-
tx_builder.clone(),
415-
)
416-
.await
417-
.expect("Failed to load test");
418-
419-
println!("Waiting for all transactions to be included in blocks...");
420-
wait_until_all_included(client.clone(), wait_time, targets)
421-
.await
422-
.unwrap();
423-
424-
let elapsed_time = time_now.elapsed();
425-
println!(
426-
"Load test round {round} finished. Elapsed time: {} seconds",
427-
elapsed_time.as_secs()
428-
);
429-
430-
if !cli.endless {
431-
break;
400+
if cli.endless {
401+
let mut round = 1;
402+
loop {
403+
run_round(round, cli.tx_amount, &accounts, &client, chain_id, &tx_builder, wait_time).await;
404+
round += 1;
432405
}
433-
round += 1;
406+
} else {
407+
run_round(1, cli.tx_amount, &accounts, &client, chain_id, &tx_builder, wait_time).await;
434408
}
435409
}
410+
411+
async fn run_round(
412+
round: u64,
413+
tx_amount: u64,
414+
accounts: &[Signer],
415+
client: &EthClient,
416+
chain_id: u64,
417+
tx_builder: &TxBuilder,
418+
wait_time: Option<Duration>,
419+
) {
420+
println!("Starting load test round {round} with {tx_amount} transactions per account...");
421+
let time_now = tokio::time::Instant::now();
422+
423+
let targets = load_test(
424+
tx_amount,
425+
accounts.to_vec(),
426+
client.clone(),
427+
chain_id,
428+
tx_builder.clone(),
429+
)
430+
.await
431+
.expect("Failed to load test");
432+
433+
println!("Waiting for all transactions to be included in blocks...");
434+
wait_until_all_included(client, wait_time, targets)
435+
.await
436+
.unwrap();
437+
438+
let elapsed_time = time_now.elapsed();
439+
println!(
440+
"Load test round {round} finished. Elapsed time: {} seconds",
441+
elapsed_time.as_secs()
442+
);
443+
}

0 commit comments

Comments
 (0)