Skip to content

Commit

Permalink
[Forge] Small improvements to FullNodeRebootStressTest
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLind committed Oct 2, 2024
1 parent 1d89592 commit 5dc12df
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions testsuite/testcases/src/fullnode_reboot_stress_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ use rand::{seq::SliceRandom, thread_rng};
use std::{sync::Arc, time::Duration};
use tokio::time::Instant;

// The buffer (in seconds) at the end of the test to allow for graceful shutdown
const END_OF_TEST_BUFFER_SECS: u64 = 60;

// The wait time (in seconds) between fullnode reboots
const WAIT_TIME_BETWEEN_REBOOTS_SECS: u64 = 10;

pub struct FullNodeRebootStressTest;

impl Test for FullNodeRebootStressTest {
Expand All @@ -30,8 +36,19 @@ impl NetworkLoadTest for FullNodeRebootStressTest {
_report: &mut TestReport,
duration: Duration,
) -> Result<()> {
// Start the test timer
let start = Instant::now();

// Ensure the total test duration is at least as long as the buffer
let end_of_test_buffer = Duration::from_secs(END_OF_TEST_BUFFER_SECS);
if duration <= end_of_test_buffer {
panic!(
"Total test duration must be at least: {:?}! Given duration: {:?}",
end_of_test_buffer, duration
);
}

// Collect all the fullnodes
let all_fullnodes = {
swarm
.read()
Expand All @@ -41,7 +58,9 @@ impl NetworkLoadTest for FullNodeRebootStressTest {
.collect::<Vec<_>>()
};

while start.elapsed() < duration {
// Reboot fullnodes until the test duration is reached
let test_reboot_duration = duration - end_of_test_buffer;
while start.elapsed() < test_reboot_duration {
{
let swarm = swarm.read().await;
let fullnode_to_reboot = {
Expand All @@ -53,7 +72,7 @@ impl NetworkLoadTest for FullNodeRebootStressTest {
fullnode_to_reboot.stop().await?;
fullnode_to_reboot.start().await?;
}
tokio::time::sleep(Duration::from_secs(10)).await;
tokio::time::sleep(Duration::from_secs(WAIT_TIME_BETWEEN_REBOOTS_SECS)).await;
}

Ok(())
Expand Down

0 comments on commit 5dc12df

Please sign in to comment.