diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f20bbe06a..527b3d5b8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -75,7 +75,7 @@ jobs: with: prefix-key: "v1-rust" # can be updated if we need to reset caches due to non-trivial change in the dependencies (for example, custom env var were set for single workspace project) - name: Install the project - run: ./scripts/run-sim --maximum-tests 1000 loop -n 10 -s + run: ./scripts/run-sim --maximum-tests 1000 --min-tick 10 --max-tick 50 loop -n 10 -s test-limbo: runs-on: blacksmith-4vcpu-ubuntu-2404 diff --git a/simulator/runner/cli.rs b/simulator/runner/cli.rs index b0776171f..f35555aa1 100644 --- a/simulator/runner/cli.rs +++ b/simulator/runner/cli.rs @@ -108,11 +108,23 @@ pub struct SimulatorCLI { #[clap(long, help = "disable Reopen-Database fault", default_value_t = false)] pub disable_reopen_database: bool, #[clap( - long = "latency_prob", + long = "latency-prob", help = "added IO latency probability", default_value_t = 1 )] pub latency_probability: usize, + #[clap( + long, + help = "Minimum tick time in microseconds for simulated time", + default_value_t = 1 + )] + pub min_tick: u64, + #[clap( + long, + help = "Maximum tick time in microseconds for simulated time", + default_value_t = 30 + )] + pub max_tick: u64, #[clap(long, help = "Enable experimental MVCC feature")] pub experimental_mvcc: bool, #[clap(long, help = "Enable experimental indexing feature")] diff --git a/simulator/runner/clock.rs b/simulator/runner/clock.rs index 2f89e93e6..ef687c5c1 100644 --- a/simulator/runner/clock.rs +++ b/simulator/runner/clock.rs @@ -8,16 +8,17 @@ use rand_chacha::ChaCha8Rng; pub struct SimulatorClock { curr_time: RefCell>, rng: RefCell, + min_tick: u64, + max_tick: u64, } impl SimulatorClock { - const MIN_TICK: u64 = 1; - const MAX_TICK: u64 = 30; - - pub fn new(rng: ChaCha8Rng) -> Self { + pub fn new(rng: ChaCha8Rng, min_tick: u64, max_tick: u64) -> Self { Self { curr_time: RefCell::new(Utc::now()), rng: RefCell::new(rng), + min_tick, + max_tick, } } @@ -26,7 +27,7 @@ impl SimulatorClock { let nanos = self .rng .borrow_mut() - .gen_range(Self::MIN_TICK..Self::MAX_TICK); + .gen_range(self.min_tick..self.max_tick); let nanos = std::time::Duration::from_micros(nanos); *time += nanos; *time diff --git a/simulator/runner/env.rs b/simulator/runner/env.rs index 675b2be08..f2de5aba1 100644 --- a/simulator/runner/env.rs +++ b/simulator/runner/env.rs @@ -247,8 +247,16 @@ impl SimulatorEnv { experimental_indexes: cli_opts.experimental_indexes, }; - let io = - Arc::new(SimulatorIO::new(seed, opts.page_size, cli_opts.latency_probability).unwrap()); + let io = Arc::new( + SimulatorIO::new( + seed, + opts.page_size, + cli_opts.latency_probability, + cli_opts.min_tick, + cli_opts.max_tick, + ) + .unwrap(), + ); // Remove existing database file if it exists let db_path = paths.db(&simulation_type, &SimulationPhase::Test); diff --git a/simulator/runner/io.rs b/simulator/runner/io.rs index b56000965..7c888cc7f 100644 --- a/simulator/runner/io.rs +++ b/simulator/runner/io.rs @@ -28,13 +28,19 @@ unsafe impl Send for SimulatorIO {} unsafe impl Sync for SimulatorIO {} impl SimulatorIO { - pub(crate) fn new(seed: u64, page_size: usize, latency_probability: usize) -> Result { + pub(crate) fn new( + seed: u64, + page_size: usize, + latency_probability: usize, + min_tick: u64, + max_tick: u64, + ) -> Result { let inner = Box::new(PlatformIO::new()?); let fault = Cell::new(false); let files = RefCell::new(Vec::new()); let rng = RefCell::new(ChaCha8Rng::seed_from_u64(seed)); let nr_run_once_faults = Cell::new(0); - let clock = SimulatorClock::new(ChaCha8Rng::seed_from_u64(seed)); + let clock = SimulatorClock::new(ChaCha8Rng::seed_from_u64(seed), min_tick, max_tick); Ok(Self { inner,