election_tests.rs 693 B

1234567891011121314151617181920212223242526272829303132333435
  1. extern crate ruaft;
  2. mod config;
  3. #[test]
  4. fn initial_election() -> std::io::Result<()> {
  5. const SERVERS: usize = 3;
  6. let cfg = config::make_config(SERVERS, false);
  7. let guard = ruaft::utils::DropGuard::new(|| cfg.cleanup());
  8. cfg.begin("Test (2A): initial election");
  9. cfg.check_one_leader()?;
  10. config::sleep_millis(50);
  11. let first_term = cfg.check_terms()?;
  12. config::sleep_election_timeouts(2);
  13. let second_term = cfg.check_terms()?;
  14. if first_term != second_term {
  15. eprintln!("Warning: term change even though there were no failures");
  16. }
  17. cfg.check_one_leader()?;
  18. cfg.end();
  19. drop(guard);
  20. Ok(())
  21. }
  22. #[test]
  23. fn re_election() {}