election_tests.rs 747 B

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