LCOV - code coverage report
Current view: top level - safekeeper/tests - random_test.rs (source / functions) Coverage Total Hit
Test: 53437f7e869ac68c86c7d3e4c20964c0156f158c.info Lines: 100.0 % 32 32
Test Date: 2024-09-20 16:14:12 Functions: 100.0 % 2 2

            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 2000 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         2001 :     for _ in 0..2000 {
      21         2000 :         let seed: u64 = rand::thread_rng().gen();
      22         2000 :         config.network = generate_network_opts(seed);
      23         2000 : 
      24         2000 :         let test = config.start(seed);
      25         2000 :         warn!("Running test with seed {}", seed);
      26              : 
      27         2000 :         let schedule = generate_schedule(seed);
      28         2000 :         test.run_schedule(&schedule).unwrap();
      29         2000 :         validate_events(test.world.take_events());
      30         2000 :         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 : }
        

Generated by: LCOV version 2.1-beta