Line data Source code
1 : use rand::Rng;
2 : use tracing::{info, warn};
3 :
4 : use crate::walproposer_sim::{
5 : log::{init_logger, init_tracing_logger},
6 : simulation::{generate_network_opts, generate_schedule, TestConfig},
7 : simulation_logs::validate_events,
8 : };
9 :
10 : pub mod walproposer_sim;
11 :
12 : // Generates 500 random seeds and runs a schedule for each of them.
13 : // If you see this test fail, please report the last seed to the
14 : // @safekeeper team.
15 : #[test]
16 1 : fn test_random_schedules() -> anyhow::Result<()> {
17 1 : let clock = init_logger();
18 1 : let mut config = TestConfig::new(Some(clock));
19 :
20 501 : for _ in 0..500 {
21 500 : let seed: u64 = rand::thread_rng().gen();
22 500 : config.network = generate_network_opts(seed);
23 500 :
24 500 : let test = config.start(seed);
25 500 : warn!("Running test with seed {}", seed);
26 :
27 500 : let schedule = generate_schedule(seed);
28 500 : test.run_schedule(&schedule).unwrap();
29 500 : validate_events(test.world.take_events());
30 500 : test.world.deallocate();
31 : }
32 :
33 1 : Ok(())
34 1 : }
35 :
36 : // After you found a seed that fails, you can insert this seed here
37 : // and run the test to see the full debug output.
38 : #[test]
39 1 : fn test_one_schedule() -> anyhow::Result<()> {
40 1 : let clock = init_tracing_logger(true);
41 1 : let mut config = TestConfig::new(Some(clock));
42 1 :
43 1 : let seed = 11047466935058776390;
44 1 : config.network = generate_network_opts(seed);
45 1 : info!("network: {:?}", config.network);
46 1 : let test = config.start(seed);
47 1 : warn!("Running test with seed {}", seed);
48 :
49 1 : let schedule = generate_schedule(seed);
50 1 : info!("schedule: {:?}", schedule);
51 1 : test.run_schedule(&schedule).unwrap();
52 1 : validate_events(test.world.take_events());
53 1 : test.world.deallocate();
54 1 :
55 1 : Ok(())
56 1 : }
|