async fn reset_run_state(
        &mut self,
        swanling_attack_run_state: &mut SwanlingAttackRunState,
    ) -> Result<(), SwanlingError> {
        // Run any configured test_start() functions.
        self.run_test_start().await.unwrap();

        // Prepare to collect metrics, if enabled.
        self.metrics = SwanlingMetrics::default();
        if !self.configuration.no_metrics {
            self.metrics
                .initialize_task_metrics(&self.task_sets, &self.configuration);
            self.metrics.display_metrics = true;
            // Only display status codes if enabled.
            self.metrics.display_status_codes = self.configuration.status_codes;
        }

        // Reset the run state.
        let std_now = std::time::Instant::now();
        swanling_attack_run_state.spawn_user_timer = std_now;
        swanling_attack_run_state.spawn_user_in_ms = 0;
        swanling_attack_run_state.spawn_user_counter = 0;
        swanling_attack_run_state.drift_timer = tokio::time::Instant::now();
        swanling_attack_run_state.metrics_header_displayed = false;
        swanling_attack_run_state.idle_status_displayed = false;
        swanling_attack_run_state.users = Vec::new();
        swanling_attack_run_state.user_channels = Vec::new();
        swanling_attack_run_state.running_metrics_timer = std_now;
        swanling_attack_run_state.display_running_metrics = false;
        swanling_attack_run_state.shutdown_after_stop = !self.configuration.no_autostart;
        swanling_attack_run_state.all_users_spawned = false;

        // If enabled, spawn a logger thread.
        let (logger_handle, all_threads_logger_tx) =
            self.configuration.setup_loggers(&self.defaults).await?;
        swanling_attack_run_state.logger_handle = logger_handle;
        swanling_attack_run_state.all_threads_logger_tx = all_threads_logger_tx;

        // If enabled, spawn a throttle thread.
        let (throttle_threads_tx, parent_to_throttle_tx) = self.setup_throttle().await;
        swanling_attack_run_state.throttle_threads_tx = throttle_threads_tx;
        swanling_attack_run_state.parent_to_throttle_tx = parent_to_throttle_tx;

        // If enabled, create an report file and confirm access.
        swanling_attack_run_state.report_file = match self.prepare_report_file().await {
            Ok(f) => f,
            Err(e) => {
                return Err(SwanlingError::InvalidOption {
                    option: "--report-file".to_string(),
                    value: self.get_report_file_path().unwrap(),
                    detail: format!("Failed to create report file: {}", e),
                })
            }
        };

        // Record when the SwanlingAttack officially started.
        self.started = Some(time::Instant::now());

        // Also record a formattable timestamp, for human readable reports.
        self.metrics.started = Some(Local::now());

        Ok(())
    }
// Reset the SwanlingAttackRunState before starting a load test. This is to allow a Controller
// to stop and start the load test multiple times, for example from a UI.
Reset the SwanlingAttackRunState before starting a load test. This is to allow a Controller
to stop and start the load test multiple times, for example from a UI.
Reset the SwanlingAttackRunState before starting a load test . This is to allow a Controller to stop and start the load test multiple times for example from a UI .
async fn reset_run_state(
        &mut self,
        swanling_attack_run_state: &mut SwanlingAttackRunState,
    ) -> Result<(), SwanlingError> {
        // Run any configured test_start() functions.
        self.run_test_start().await.unwrap();
        // Prepare to collect metrics, if enabled.
        self.metrics = SwanlingMetrics::default();
        if !self.configuration.no_metrics {
            self.metrics
                .initialize_task_metrics(&self.task_sets, &self.configuration);
            self.metrics.display_metrics = true;
            // Only display status codes if enabled.
            self.metrics.display_status_codes = self.configuration.status_codes;
        }
        // Reset the run state.
        let std_now = std::time::Instant::now();
        swanling_attack_run_state.spawn_user_timer = std_now;
        swanling_attack_run_state.spawn_user_in_ms = 0;
        swanling_attack_run_state.spawn_user_counter = 0;
        swanling_attack_run_state.drift_timer = tokio::time::Instant::now();
        swanling_attack_run_state.metrics_header_displayed = false;
        swanling_attack_run_state.idle_status_displayed = false;
        swanling_attack_run_state.users = Vec::new();
        swanling_attack_run_state.user_channels = Vec::new();
        swanling_attack_run_state.running_metrics_timer = std_now;
        swanling_attack_run_state.display_running_metrics = false;
        swanling_attack_run_state.shutdown_after_stop = !self.configuration.no_autostart;
        swanling_attack_run_state.all_users_spawned = false;
        // If enabled, spawn a logger thread.
        let (logger_handle, all_threads_logger_tx) =
            self.configuration.setup_loggers(&self.defaults).await?;
        swanling_attack_run_state.logger_handle = logger_handle;
        swanling_attack_run_state.all_threads_logger_tx = all_threads_logger_tx;
        // If enabled, spawn a throttle thread.
        let (throttle_threads_tx, parent_to_throttle_tx) = self.setup_throttle().await;
        swanling_attack_run_state.throttle_threads_tx = throttle_threads_tx;
        swanling_attack_run_state.parent_to_throttle_tx = parent_to_throttle_tx;
        // If enabled, create an report file and confirm access.
        swanling_attack_run_state.report_file = match self.prepare_report_file().await {
            Ok(f) => f,
            Err(e) => {
                return Err(SwanlingError::InvalidOption {
                    option: "--report-file".to_string(),
                    value: self.get_report_file_path().unwrap(),
                    detail: format!("Failed to create report file: {}", e),
                })
            }
        };
        // Record when the SwanlingAttack officially started.
        self.started = Some(time::Instant::now());
        // Also record a formattable timestamp, for human readable reports.
        self.metrics.started = Some(Local::now());
        Ok(())
    }
async fn reset_run_state ( & mut self , swanling_attack_run_state : & mut SwanlingAttackRunState , ) -> Result < ( ) , SwanlingError > { // Run any configured test_start() functions. self . run_test_start ( ) . await . unwrap ( ) ; // Prepare to collect metrics, if enabled. self . metrics = SwanlingMetrics :: default ( ) ; if ! self . configuration . no_metrics { self . metrics . initialize_task_metrics ( & self . task_sets , & self . configuration ) ; self . metrics . display_metrics = true ; // Only display status codes if enabled. self . metrics . display_status_codes = self . configuration . status_codes ; } // Reset the run state. let std_now = std :: time :: Instant :: now ( ) ; swanling_attack_run_state . spawn_user_timer = std_now ; swanling_attack_run_state . spawn_user_in_ms = 0 ; swanling_attack_run_state . spawn_user_counter = 0 ; swanling_attack_run_state . drift_timer = tokio :: time :: Instant :: now ( ) ; swanling_attack_run_state . metrics_header_displayed = false ; swanling_attack_run_state . idle_status_displayed = false ; swanling_attack_run_state . users = Vec :: new ( ) ; swanling_attack_run_state . user_channels = Vec :: new ( ) ; swanling_attack_run_state . running_metrics_timer = std_now ; swanling_attack_run_state . display_running_metrics = false ; swanling_attack_run_state . shutdown_after_stop = ! self . configuration . no_autostart ; swanling_attack_run_state . all_users_spawned = false ; // If enabled, spawn a logger thread. let ( logger_handle , all_threads_logger_tx ) = self . configuration . setup_loggers ( & self . defaults ) . await ? ; swanling_attack_run_state . logger_handle = logger_handle ; swanling_attack_run_state . all_threads_logger_tx = all_threads_logger_tx ; // If enabled, spawn a throttle thread. let ( throttle_threads_tx , parent_to_throttle_tx ) = self . setup_throttle ( ) . await ; swanling_attack_run_state . throttle_threads_tx = throttle_threads_tx ; swanling_attack_run_state . parent_to_throttle_tx = parent_to_throttle_tx ; // If enabled, create an report file and confirm access. swanling_attack_run_state . report_file = match self . prepare_report_file ( ) . await { Ok ( f ) => f , Err ( e ) => { return Err ( SwanlingError :: InvalidOption { option : " " . to_string ( ) , value : self . get_report_file_path ( ) . unwrap ( ) , detail : format ! ( " " e ) , } ) } } ; // Record when the SwanlingAttack officially started. self . started = Some ( time :: Instant :: now ( ) ) ; // Also record a formattable timestamp, for human readable reports. self . metrics . started = Some ( Local :: now ( ) ) ; Ok ( ( ) ) }
Reset the SwanlingAttackRunState before starting a load test.
Reset the SwanlingAttackRunState before starting a load test .
&mut self
swanling_attack_run_state
&mut SwanlingAttackRunState