1use std::time::Duration;
2
3use serde::{Deserialize, Serialize};
4
5pub trait ExecutorConfig {
6 fn split(&self, times: usize) -> Config;
7}
8
9#[derive(Serialize, Deserialize, Debug, Clone)]
10pub enum Config {
11 ConstantArrivalRate(ConstantArrivalRateConfig),
12}
13
14impl Config {
15 pub fn split(&self, times: usize) -> Config {
16 match self {
17 Config::ConstantArrivalRate(config) => config.split(times),
18 }
19 }
20}
21
22#[derive(Serialize, Deserialize, Debug, Clone)]
23pub struct ConstantArrivalRateConfig {
24 pub duration: Duration,
25 pub rate: usize,
26 pub time_unit: Duration,
27 pub allocated_vus: usize,
28}
29
30impl ExecutorConfig for ConstantArrivalRateConfig {
31 fn split(&self, times: usize) -> Config {
32 let mut new_config = self.clone();
33
34 new_config.rate /= times;
35 if new_config.rate == 0 {
42 new_config.rate = 1;
43 }
44
45 Config::ConstantArrivalRate(new_config)
46 }
47}
48
49impl Default for ConstantArrivalRateConfig {
50 fn default() -> Self {
51 Self {
52 duration: Default::default(),
53 rate: Default::default(),
54 time_unit: Duration::from_secs(1),
55 allocated_vus: Default::default(),
56 }
57 }
58}