diff --git a/Cargo.toml b/Cargo.toml index 9c9fe7cbb..6e829363d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,9 @@ quick-error = "1.2.2" rand = "0.5.4" fxhash = "0.2.1" +[dev-dependencies] +env_logger = "0.5.12" + [badges] travis-ci = { repository = "pingcap/raft-rs" } diff --git a/tests/cases/test_raft.rs b/tests/cases/test_raft.rs index 5b385c548..77ace7b9e 100644 --- a/tests/cases/test_raft.rs +++ b/tests/cases/test_raft.rs @@ -37,6 +37,7 @@ use raft::eraftpb::{ Snapshot, }; use rand; +use env_logger; use raft::storage::MemStorage; use raft::*; @@ -425,6 +426,7 @@ impl Network { #[test] fn test_progress_become_probe() { + let _ = env_logger::try_init(); let matched = 1u64; let mut tests = vec![ ( @@ -460,6 +462,7 @@ fn test_progress_become_probe() { #[test] fn test_progress_become_replicate() { + let _ = env_logger::try_init(); let mut p = new_progress(ProgressState::Probe, 1, 5, 0, 256); p.become_replicate(); @@ -470,6 +473,7 @@ fn test_progress_become_replicate() { #[test] fn test_progress_become_snapshot() { + let _ = env_logger::try_init(); let mut p = new_progress(ProgressState::Probe, 1, 5, 0, 256); p.become_snapshot(10); assert_eq!(p.state, ProgressState::Snapshot); @@ -479,6 +483,7 @@ fn test_progress_become_snapshot() { #[test] fn test_progress_update() { + let _ = env_logger::try_init(); let (prev_m, prev_n) = (3u64, 5u64); let tests = vec![ (prev_m - 1, prev_m, prev_n, false), @@ -507,6 +512,7 @@ fn test_progress_update() { #[test] fn test_progress_maybe_decr() { + let _ = env_logger::try_init(); let tests = vec![ // state replicate and rejected is not greater than match (ProgressState::Replicate, 5, 10, 5, 5, false, 10), @@ -546,6 +552,7 @@ fn test_progress_maybe_decr() { #[test] fn test_progress_is_paused() { + let _ = env_logger::try_init(); let tests = vec![ (ProgressState::Probe, false, false), (ProgressState::Probe, true, true), @@ -571,6 +578,7 @@ fn test_progress_is_paused() { // will reset progress.paused. #[test] fn test_progress_resume() { + let _ = env_logger::try_init(); let mut p = Progress { next_idx: 2, paused: true, @@ -587,6 +595,7 @@ fn test_progress_resume() { // heartbeat response. #[test] fn test_progress_resume_by_heartbeat_resp() { + let _ = env_logger::try_init(); let mut raft = new_test_raft(1, vec![1, 2], 5, 1, new_storage()); raft.become_candidate(); raft.become_leader(); @@ -604,6 +613,7 @@ fn test_progress_resume_by_heartbeat_resp() { #[test] fn test_progress_paused() { + let _ = env_logger::try_init(); let mut raft = new_test_raft(1, vec![1, 2], 5, 1, new_storage()); raft.become_candidate(); raft.become_leader(); @@ -623,11 +633,13 @@ fn test_progress_paused() { #[test] fn test_leader_election() { + let _ = env_logger::try_init(); test_leader_election_with_config(false); } #[test] fn test_leader_election_pre_vote() { + let _ = env_logger::try_init(); test_leader_election_with_config(true); } @@ -702,11 +714,13 @@ fn test_leader_election_with_config(pre_vote: bool) { #[test] fn test_leader_cycle() { + let _ = env_logger::try_init(); test_leader_cycle_with_config(false) } #[test] fn test_leader_cycle_pre_vote() { + let _ = env_logger::try_init(); test_leader_cycle_with_config(true) } @@ -743,11 +757,13 @@ fn test_leader_cycle_with_config(pre_vote: bool) { #[test] fn test_leader_election_overwrite_newer_logs() { + let _ = env_logger::try_init(); test_leader_election_overwrite_newer_logs_with_config(false); } #[test] fn test_leader_election_overwrite_newer_logs_pre_vote() { + let _ = env_logger::try_init(); test_leader_election_overwrite_newer_logs_with_config(true); } @@ -823,11 +839,13 @@ fn test_leader_election_overwrite_newer_logs_with_config(pre_vote: bool) { #[test] fn test_vote_from_any_state() { + let _ = env_logger::try_init(); test_vote_from_any_state_for_type(MessageType::MsgRequestVote); } #[test] fn test_prevote_from_any_state() { + let _ = env_logger::try_init(); test_vote_from_any_state_for_type(MessageType::MsgRequestPreVote); } @@ -935,6 +953,7 @@ fn test_vote_from_any_state_for_type(vt: MessageType) { #[test] fn test_log_replicatioin() { + let _ = env_logger::try_init(); let mut tests = vec![ ( Network::new(vec![None, None, None]), @@ -990,6 +1009,7 @@ fn test_log_replicatioin() { #[test] fn test_single_node_commit() { + let _ = env_logger::try_init(); let mut tt = Network::new(vec![None]); tt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); tt.send(vec![new_message(1, 1, MessageType::MsgPropose, 1)]); @@ -1003,6 +1023,7 @@ fn test_single_node_commit() { // filtered. #[test] fn test_cannot_commit_without_new_term_entry() { + let _ = env_logger::try_init(); let mut tt = Network::new(vec![None, None, None, None, None]); tt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -1040,6 +1061,7 @@ fn test_cannot_commit_without_new_term_entry() { // when leader changes, no new proposal comes in. #[test] fn test_commit_without_new_term_entry() { + let _ = env_logger::try_init(); let mut tt = Network::new(vec![None, None, None, None, None]); tt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -1066,6 +1088,7 @@ fn test_commit_without_new_term_entry() { #[test] fn test_dueling_candidates() { + let _ = env_logger::try_init(); let a = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage()); let b = new_test_raft(2, vec![1, 2, 3], 10, 1, new_storage()); let c = new_test_raft(3, vec![1, 2, 3], 10, 1, new_storage()); @@ -1119,6 +1142,7 @@ fn test_dueling_candidates() { #[test] fn test_dueling_pre_candidates() { + let _ = env_logger::try_init(); let a = new_test_raft_with_prevote(1, vec![1, 2, 3], 10, 1, new_storage(), true); let b = new_test_raft_with_prevote(2, vec![1, 2, 3], 10, 1, new_storage(), true); let c = new_test_raft_with_prevote(3, vec![1, 2, 3], 10, 1, new_storage(), true); @@ -1168,6 +1192,7 @@ fn test_dueling_pre_candidates() { #[test] fn test_candidate_concede() { + let _ = env_logger::try_init(); let mut tt = Network::new(vec![None, None, None]); tt.isolate(1); @@ -1202,6 +1227,7 @@ fn test_candidate_concede() { #[test] fn test_single_node_candidate() { + let _ = env_logger::try_init(); let mut tt = Network::new(vec![None]); tt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -1210,6 +1236,7 @@ fn test_single_node_candidate() { #[test] fn test_sinle_node_pre_candidate() { + let _ = env_logger::try_init(); let mut tt = Network::new_with_config(vec![None], true); tt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -1218,6 +1245,7 @@ fn test_sinle_node_pre_candidate() { #[test] fn test_old_messages() { + let _ = env_logger::try_init(); let mut tt = Network::new(vec![None, None, None]); // make 0 leader @ term 3 tt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -1251,6 +1279,7 @@ fn test_old_messages() { #[test] fn test_proposal() { + let _ = env_logger::try_init(); let mut tests = vec![ (Network::new(vec![None, None, None]), true), (Network::new(vec![None, None, NOP_STEPPER]), true), @@ -1297,6 +1326,7 @@ fn test_proposal() { #[test] fn test_proposal_by_proxy() { + let _ = env_logger::try_init(); let mut tests = vec![ Network::new(vec![None, None, None]), Network::new(vec![None, None, NOP_STEPPER]), @@ -1327,6 +1357,7 @@ fn test_proposal_by_proxy() { #[test] fn test_commit() { + let _ = env_logger::try_init(); let mut tests = vec![ // single (vec![1u64], vec![empty_entry(1, 1)], 1u64, 1u64), @@ -1420,6 +1451,7 @@ fn test_commit() { #[test] fn test_pass_election_timeout() { + let _ = env_logger::try_init(); let tests = vec![ (5, 0f64, false), (10, 0.1, true), @@ -1453,6 +1485,7 @@ fn test_pass_election_timeout() { // actual stepX function. #[test] fn test_step_ignore_old_term_msg() { + let _ = env_logger::try_init(); let mut sm = new_test_raft(1, vec![1], 10, 1, new_storage()); let panic_before_step_state = Box::new(|_: &Message| panic!("before step state function hook called unexpectedly")); @@ -1471,6 +1504,7 @@ fn test_step_ignore_old_term_msg() { // 3. If leaderCommit > commitIndex, set commitIndex = min(leaderCommit, index of last new entry). #[test] fn test_handle_msg_append() { + let _ = env_logger::try_init(); let nm = |term, log_term, index, commit, ents: Option>| { let mut m = Message::new(); m.set_msg_type(MessageType::MsgAppend); @@ -1540,6 +1574,7 @@ fn test_handle_msg_append() { // test_handle_heartbeat ensures that the follower commits to the commit in the message. #[test] fn test_handle_heartbeat() { + let _ = env_logger::try_init(); let commit = 2u64; let nw = |f, to, term, commit| { let mut m = new_message(f, to, MessageType::MsgHeartbeat, 0); @@ -1584,6 +1619,7 @@ fn test_handle_heartbeat() { // test_handle_heartbeat_resp ensures that we re-send log entries when we get a heartbeat response. #[test] fn test_handle_heartbeat_resp() { + let _ = env_logger::try_init(); let store = new_storage(); store .wl() @@ -1627,6 +1663,7 @@ fn test_handle_heartbeat_resp() { // related issue: https://github.com/coreos/etcd/issues/7571 #[test] fn test_raft_frees_read_only_mem() { + let _ = env_logger::try_init(); let mut sm = new_test_raft(1, vec![1, 2], 5, 1, new_storage()); sm.become_candidate(); sm.become_leader(); @@ -1668,6 +1705,7 @@ fn test_raft_frees_read_only_mem() { // MsgAppResp. #[test] fn test_msg_append_response_wait_reset() { + let _ = env_logger::try_init(); let mut sm = new_test_raft(1, vec![1, 2, 3], 5, 1, new_storage()); sm.become_candidate(); sm.become_leader(); @@ -1713,6 +1751,7 @@ fn test_msg_append_response_wait_reset() { #[test] fn test_recv_msg_request_vote() { + let _ = env_logger::try_init(); test_recv_msg_request_vote_for_type(MessageType::MsgRequestVote); } @@ -1793,6 +1832,7 @@ fn test_recv_msg_request_vote_for_type(msg_type: MessageType) { #[test] fn test_state_transition() { + let _ = env_logger::try_init(); let mut tests = vec![ ( StateRole::Follower, @@ -1905,6 +1945,7 @@ fn test_state_transition() { #[test] fn test_all_server_stepdown() { + let _ = env_logger::try_init(); let mut tests = vec![ (StateRole::Follower, StateRole::Follower, 3, 0), (StateRole::PreCandidate, StateRole::Follower, 3, 0), @@ -1966,11 +2007,13 @@ fn test_all_server_stepdown() { #[test] fn test_candidate_reset_term_msg_heartbeat() { + let _ = env_logger::try_init(); test_candidate_reset_term(MessageType::MsgHeartbeat) } #[test] fn test_candidate_reset_term_msg_append() { + let _ = env_logger::try_init(); test_candidate_reset_term(MessageType::MsgAppend) } @@ -2031,6 +2074,7 @@ fn test_candidate_reset_term(message_type: MessageType) { #[test] fn test_leader_stepdown_when_quorum_active() { + let _ = env_logger::try_init(); let mut sm = new_test_raft(1, vec![1, 2, 3], 5, 1, new_storage()); sm.check_quorum = true; sm.become_candidate(); @@ -2048,6 +2092,7 @@ fn test_leader_stepdown_when_quorum_active() { #[test] fn test_leader_stepdown_when_quorum_lost() { + let _ = env_logger::try_init(); let mut sm = new_test_raft(1, vec![1, 2, 3], 5, 1, new_storage()); sm.check_quorum = true; @@ -2064,6 +2109,7 @@ fn test_leader_stepdown_when_quorum_lost() { #[test] fn test_leader_superseding_with_check_quorum() { + let _ = env_logger::try_init(); let mut a = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage()); let mut b = new_test_raft(2, vec![1, 2, 3], 10, 1, new_storage()); let mut c = new_test_raft(3, vec![1, 2, 3], 10, 1, new_storage()); @@ -2104,6 +2150,7 @@ fn test_leader_superseding_with_check_quorum() { #[test] fn test_leader_election_with_check_quorum() { + let _ = env_logger::try_init(); let mut a = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage()); let mut b = new_test_raft(2, vec![1, 2, 3], 10, 1, new_storage()); let mut c = new_test_raft(3, vec![1, 2, 3], 10, 1, new_storage()); @@ -2165,6 +2212,7 @@ fn test_leader_election_with_check_quorum() { // leader is expected to step down and adopt the candidate's term #[test] fn test_free_stuck_candidate_with_check_quorum() { + let _ = env_logger::try_init(); let mut a = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage()); let mut b = new_test_raft(2, vec![1, 2, 3], 10, 1, new_storage()); let mut c = new_test_raft(3, vec![1, 2, 3], 10, 1, new_storage()); @@ -2218,6 +2266,7 @@ fn test_free_stuck_candidate_with_check_quorum() { #[test] fn test_non_promotable_voter_which_check_quorum() { + let _ = env_logger::try_init(); let mut a = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); let mut b = new_test_raft(2, vec![1], 10, 1, new_storage()); @@ -2258,6 +2307,7 @@ fn test_non_promotable_voter_which_check_quorum() { /// to step down. #[test] fn test_disruptive_follower() { + let _ = env_logger::try_init(); let mut n1 = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage()); let mut n2 = new_test_raft(2, vec![1, 2, 3], 10, 1, new_storage()); let mut n3 = new_test_raft(3, vec![1, 2, 3], 10, 1, new_storage()); @@ -2348,6 +2398,7 @@ fn test_disruptive_follower() { /// current leader to step down, thus less disruptions. #[test] fn test_disruptive_follower_pre_vote() { + let _ = env_logger::try_init(); let mut n1 = new_test_raft_with_prevote(1, vec![1, 2, 3], 10, 1, new_storage(), true); let mut n2 = new_test_raft_with_prevote(2, vec![1, 2, 3], 10, 1, new_storage(), true); let mut n3 = new_test_raft_with_prevote(3, vec![1, 2, 3], 10, 1, new_storage(), true); @@ -2398,6 +2449,7 @@ fn test_disruptive_follower_pre_vote() { #[test] fn test_read_only_option_safe() { + let _ = env_logger::try_init(); let a = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage()); let b = new_test_raft(2, vec![1, 2, 3], 10, 1, new_storage()); let c = new_test_raft(3, vec![1, 2, 3], 10, 1, new_storage()); @@ -2467,6 +2519,7 @@ fn test_read_only_option_safe() { #[test] fn test_read_only_option_lease() { + let _ = env_logger::try_init(); let mut a = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage()); let mut b = new_test_raft(2, vec![1, 2, 3], 10, 1, new_storage()); let mut c = new_test_raft(3, vec![1, 2, 3], 10, 1, new_storage()); @@ -2542,6 +2595,7 @@ fn test_read_only_option_lease() { #[test] fn test_read_only_option_lease_without_check_quorum() { + let _ = env_logger::try_init(); let mut a = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage()); let mut b = new_test_raft(2, vec![1, 2, 3], 10, 1, new_storage()); let mut c = new_test_raft(3, vec![1, 2, 3], 10, 1, new_storage()); @@ -2573,6 +2627,7 @@ fn test_read_only_option_lease_without_check_quorum() { // when it commits at least one log entry at it term. #[test] fn test_read_only_for_new_leader() { + let _ = env_logger::try_init(); let heartbeat_ticks = 1; let node_configs = vec![(1, 1, 1, 0), (2, 2, 2, 2), (3, 2, 2, 2)]; let mut peers = vec![]; @@ -2649,6 +2704,7 @@ fn test_read_only_for_new_leader() { #[test] fn test_leader_append_response() { + let _ = env_logger::try_init(); // initial progress: match = 0; next = 3 let mut tests = vec![ (3, true, 0, 3, 0, 0, 0), // stale resp; no replies @@ -2717,6 +2773,7 @@ fn test_leader_append_response() { // send a MsgApp with m.Index = 0, m.LogTerm=0 and empty entries. #[test] fn test_bcast_beat() { + let _ = env_logger::try_init(); let offset = 1000u64; // make a state machine with log.offset = 1000 let s = new_snapshot(offset, 1, vec![1, 2, 3]); @@ -2792,6 +2849,7 @@ fn test_bcast_beat() { // tests the output of the statemachine when receiving MsgBeat #[test] fn test_recv_msg_beat() { + let _ = env_logger::try_init(); let mut tests = vec![ (StateRole::Leader, 2), // candidate and follower should ignore MsgBeat @@ -2826,6 +2884,7 @@ fn test_recv_msg_beat() { #[test] fn test_leader_increase_next() { + let _ = env_logger::try_init(); let previous_ents = vec![empty_entry(1, 1), empty_entry(1, 2), empty_entry(1, 3)]; let mut tests = vec![ // state replicate; optimistically increase next @@ -2861,6 +2920,7 @@ fn test_leader_increase_next() { #[test] fn test_send_append_for_progress_probe() { + let _ = env_logger::try_init(); let mut r = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); r.become_candidate(); r.become_leader(); @@ -2911,6 +2971,7 @@ fn test_send_append_for_progress_probe() { #[test] fn test_send_append_for_progress_replicate() { + let _ = env_logger::try_init(); let mut r = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); r.become_candidate(); r.become_leader(); @@ -2926,6 +2987,7 @@ fn test_send_append_for_progress_replicate() { #[test] fn test_send_append_for_progress_snapshot() { + let _ = env_logger::try_init(); let mut r = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); r.become_candidate(); r.become_leader(); @@ -2941,6 +3003,7 @@ fn test_send_append_for_progress_snapshot() { #[test] fn test_recv_msg_unreachable() { + let _ = env_logger::try_init(); let previous_ents = vec![empty_entry(1, 1), empty_entry(1, 2), empty_entry(1, 3)]; let s = new_storage(); s.wl().append(&previous_ents).expect(""); @@ -2965,6 +3028,7 @@ fn test_recv_msg_unreachable() { #[test] fn test_restore() { + let _ = env_logger::try_init(); // magic number let s = new_snapshot(11, 11, vec![1, 2, 3]); @@ -2984,6 +3048,7 @@ fn test_restore() { #[test] fn test_restore_ignore_snapshot() { + let _ = env_logger::try_init(); let previous_ents = vec![empty_entry(1, 1), empty_entry(1, 2), empty_entry(1, 3)]; let commit = 1u64; let mut sm = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); @@ -3004,6 +3069,7 @@ fn test_restore_ignore_snapshot() { #[test] fn test_provide_snap() { + let _ = env_logger::try_init(); // restore the state machine from a snapshot so it has a compacted log and a snapshot let s = new_snapshot(11, 11, vec![1, 2]); // magic number @@ -3027,6 +3093,7 @@ fn test_provide_snap() { #[test] fn test_ignore_providing_snapshot() { + let _ = env_logger::try_init(); // restore the state machine from a snapshot so it has a compacted log and a snapshot let s = new_snapshot(11, 11, vec![1, 2]); // magic number let mut sm = new_test_raft(1, vec![1], 10, 1, new_storage()); @@ -3048,6 +3115,7 @@ fn test_ignore_providing_snapshot() { #[test] fn test_restore_from_snap_msg() { + let _ = env_logger::try_init(); let s = new_snapshot(11, 11, vec![1, 2]); // magic number let mut sm = new_test_raft(2, vec![1, 2], 10, 1, new_storage()); let mut m = new_message(1, 0, MessageType::MsgSnapshot, 0); @@ -3063,6 +3131,7 @@ fn test_restore_from_snap_msg() { #[test] fn test_slow_node_restore() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3107,6 +3176,7 @@ fn test_slow_node_restore() { // it appends the entry to log and sets pendingConf to be true. #[test] fn test_step_config() { + let _ = env_logger::try_init(); // a raft that cannot make progress let mut r = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); r.become_candidate(); @@ -3125,6 +3195,7 @@ fn test_step_config() { // the proposal to noop and keep its original state. #[test] fn test_step_ignore_config() { + let _ = env_logger::try_init(); // a raft that cannot make progress let mut r = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); r.become_candidate(); @@ -3151,6 +3222,7 @@ fn test_step_ignore_config() { // based on uncommitted entries. #[test] fn test_new_leader_pending_config() { + let _ = env_logger::try_init(); let mut tests = vec![(false, 0), (true, 1)]; for (i, (add_entry, wpending_index)) in tests.drain(..).enumerate() { let mut r = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); @@ -3174,6 +3246,7 @@ fn test_new_leader_pending_config() { // test_add_node tests that add_node could update nodes correctly. #[test] fn test_add_node() { + let _ = env_logger::try_init(); let mut r = new_test_raft(1, vec![1], 10, 1, new_storage()); r.add_node(2); assert_eq!(r.prs().nodes(), vec![1, 2]); @@ -3181,6 +3254,7 @@ fn test_add_node() { #[test] fn test_add_node_check_quorum() { + let _ = env_logger::try_init(); let mut r = new_test_raft(1, vec![1], 10, 1, new_storage()); r.check_quorum = true; @@ -3212,6 +3286,7 @@ fn test_add_node_check_quorum() { // and removed list correctly. #[test] fn test_remove_node() { + let _ = env_logger::try_init(); let mut r = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); r.remove_node(2); assert_eq!(r.prs().nodes(), vec![1]); @@ -3223,6 +3298,7 @@ fn test_remove_node() { #[test] fn test_promotable() { + let _ = env_logger::try_init(); let id = 1u64; let mut tests = vec![ (vec![1], true), @@ -3240,6 +3316,7 @@ fn test_promotable() { #[test] fn test_raft_nodes() { + let _ = env_logger::try_init(); let mut tests = vec![ (vec![1, 2, 3], vec![1, 2, 3]), (vec![3, 2, 1], vec![1, 2, 3]), @@ -3254,11 +3331,13 @@ fn test_raft_nodes() { #[test] fn test_campaign_while_leader() { + let _ = env_logger::try_init(); test_campaign_while_leader_with_pre_vote(false); } #[test] fn test_pre_campaign_while_leader() { + let _ = env_logger::try_init(); test_campaign_while_leader_with_pre_vote(true); } @@ -3279,6 +3358,7 @@ fn test_campaign_while_leader_with_pre_vote(pre_vote: bool) { // committed when a config change reduces the quorum requirements. #[test] fn test_commit_after_remove_node() { + let _ = env_logger::try_init(); // Create a cluster with two nodes. let s = new_storage(); let mut r = new_test_raft(1, vec![1, 2], 5, 1, s.clone()); @@ -3329,6 +3409,7 @@ fn test_commit_after_remove_node() { // if the transferee has the most up-to-date log entries when transfer starts. #[test] fn test_leader_transfer_to_uptodate_node() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3352,6 +3433,7 @@ fn test_leader_transfer_to_uptodate_node() { // to the follower. #[test] fn test_leader_transfer_to_uptodate_node_from_follower() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3372,6 +3454,7 @@ fn test_leader_transfer_to_uptodate_node_from_follower() { // even the current leader is still under its leader lease #[test] fn test_leader_transfer_with_check_quorum() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); for i in 1..4 { let r = &mut nt.peers.get_mut(&i).unwrap(); @@ -3406,6 +3489,7 @@ fn test_leader_transfer_with_check_quorum() { #[test] fn test_leader_transfer_to_slow_follower() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3423,6 +3507,7 @@ fn test_leader_transfer_to_slow_follower() { #[test] fn test_leader_transfer_after_snapshot() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3459,6 +3544,7 @@ fn test_leader_transfer_after_snapshot() { #[test] fn test_leader_transfer_to_self() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3469,6 +3555,7 @@ fn test_leader_transfer_to_self() { #[test] fn test_leader_transfer_to_non_existing_node() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3479,6 +3566,7 @@ fn test_leader_transfer_to_non_existing_node() { #[test] fn test_leader_transfer_timeout() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3502,6 +3590,7 @@ fn test_leader_transfer_timeout() { #[test] fn test_leader_transfer_ignore_proposal() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3526,6 +3615,7 @@ fn test_leader_transfer_ignore_proposal() { #[test] fn test_leader_transfer_receive_higher_term_vote() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3547,6 +3637,7 @@ fn test_leader_transfer_receive_higher_term_vote() { #[test] fn test_leader_transfer_remove_node() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3565,6 +3656,7 @@ fn test_leader_transfer_remove_node() { // back to self when last transfer is pending. #[test] fn test_leader_transfer_back() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3583,6 +3675,7 @@ fn test_leader_transfer_back() { // when last transfer is pending. #[test] fn test_leader_transfer_second_transfer_to_another_node() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3601,6 +3694,7 @@ fn test_leader_transfer_second_transfer_to_another_node() { // to the same node should not extend the timeout while the first one is pending. #[test] fn test_leader_transfer_second_transfer_to_same_node() { + let _ = env_logger::try_init(); let mut nt = Network::new(vec![None, None, None]); nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); @@ -3641,6 +3735,7 @@ fn check_leader_transfer_state(r: &Raft, state: StateRole, lead: u64 // transitioned to StateRole::Leader) #[test] fn test_transfer_non_member() { + let _ = env_logger::try_init(); let mut raft = new_test_raft(1, vec![2, 3, 4], 5, 1, new_storage()); raft.step(new_message(2, 1, MessageType::MsgTimeoutNow, 0)) .expect("");; @@ -3659,6 +3754,7 @@ fn test_transfer_non_member() { // enabled. #[test] fn test_node_with_smaller_term_can_complete_election() { + let _ = env_logger::try_init(); let mut n1 = new_test_raft_with_prevote(1, vec![1, 2, 3], 10, 1, new_storage(), true); let mut n2 = new_test_raft_with_prevote(2, vec![1, 2, 3], 10, 1, new_storage(), true); let mut n3 = new_test_raft_with_prevote(3, vec![1, 2, 3], 10, 1, new_storage(), true); @@ -3732,6 +3828,7 @@ pub fn new_test_learner_raft( // even when times out. #[test] fn test_learner_election_timeout() { + let _ = env_logger::try_init(); let mut n1 = new_test_learner_raft(1, vec![1], vec![2], 10, 1, new_storage()); n1.become_follower(1, INVALID_ID); @@ -3752,6 +3849,7 @@ fn test_learner_election_timeout() { // it is promoted to a normal peer. #[test] fn test_learner_promotion() { + let _ = env_logger::try_init(); let mut n1 = new_test_learner_raft(1, vec![1], vec![2], 10, 1, new_storage()); n1.become_follower(1, INVALID_ID); @@ -3803,6 +3901,7 @@ fn test_learner_promotion() { // TestLearnerLogReplication tests that a learner can receive entries from the leader. #[test] fn test_learner_log_replication() { + let _ = env_logger::try_init(); let n1 = new_test_learner_raft(1, vec![1], vec![2], 10, 1, new_storage()); let n2 = new_test_learner_raft(2, vec![1], vec![2], 10, 1, new_storage()); let mut network = Network::new(vec![Some(n1), Some(n2)]); @@ -3858,6 +3957,7 @@ fn test_learner_log_replication() { // TestRestoreWithLearner restores a snapshot which contains learners. #[test] fn test_restore_with_learner() { + let _ = env_logger::try_init(); let mut s = new_snapshot(11, 11, vec![1, 2]); s.mut_metadata().mut_conf_state().mut_learners().push(3); @@ -3886,6 +3986,7 @@ fn test_restore_with_learner() { // when restores snapshot. #[test] fn test_restore_invalid_learner() { + let _ = env_logger::try_init(); let mut s = new_snapshot(11, 11, vec![1, 2]); s.mut_metadata().mut_conf_state().mut_learners().push(3); @@ -3898,6 +3999,7 @@ fn test_restore_invalid_learner() { // restoring snapshot. #[test] fn test_restore_learner_promotion() { + let _ = env_logger::try_init(); let s = new_snapshot(11, 11, vec![1, 2, 3]); let mut sm = new_test_learner_raft(3, vec![1, 2], vec![3], 10, 1, new_storage()); assert!(sm.is_learner); @@ -3908,6 +4010,7 @@ fn test_restore_learner_promotion() { // TestLearnerReceiveSnapshot tests that a learner can receive a snpahost from leader. #[test] fn test_learner_receive_snapshot() { + let _ = env_logger::try_init(); let mut s = new_snapshot(11, 11, vec![1]); s.mut_metadata().mut_conf_state().mut_learners().push(2); @@ -3945,6 +4048,7 @@ fn test_learner_receive_snapshot() { // TestAddLearner tests that addLearner could update nodes correctly. #[test] fn test_add_learner() { + let _ = env_logger::try_init(); let mut n1 = new_test_raft(1, vec![1], 10, 1, new_storage()); n1.add_learner(2); @@ -3956,6 +4060,7 @@ fn test_add_learner() { // and removed list correctly. #[test] fn test_remove_learner() { + let _ = env_logger::try_init(); let mut n1 = new_test_learner_raft(1, vec![1], vec![2], 10, 1, new_storage()); n1.remove_node(2); assert_eq!(n1.prs().nodes(), vec![1]); @@ -4018,6 +4123,7 @@ fn new_prevote_migration_cluster() -> Network { #[test] fn test_prevote_migration_can_complete_election() { + let _ = env_logger::try_init(); // n1 is leader with term 2 // n2 is follower with term 2 // n3 is pre-candidate with term 4, and less log @@ -4047,6 +4153,7 @@ fn test_prevote_migration_can_complete_election() { #[test] fn test_prevote_migration_with_free_stuck_pre_candidate() { + let _ = env_logger::try_init(); let mut nt = new_prevote_migration_cluster(); // n1 is leader with term 2 @@ -4076,6 +4183,7 @@ fn test_prevote_migration_with_free_stuck_pre_candidate() { #[test] fn test_learner_respond_vote() { + let _ = env_logger::try_init(); let mut n1 = new_test_learner_raft(1, vec![1, 2], vec![3], 10, 1, new_storage()); n1.become_follower(1, INVALID_ID); n1.reset_randomized_election_timeout(); @@ -4104,6 +4212,7 @@ fn test_learner_respond_vote() { #[test] fn test_election_tick_range() { + let _ = env_logger::try_init(); let mut cfg = new_test_config(1, vec![1, 2, 3], 10, 1); let mut raft = Raft::new(&cfg, new_storage()); for _ in 0..1000 { @@ -4139,6 +4248,7 @@ fn test_election_tick_range() { // election in next round. #[test] fn test_prevote_with_split_vote() { + let _ = env_logger::try_init(); let peers = (1..=3).map(|id| { let mut raft = new_test_raft_with_prevote(id, vec![1, 2, 3], 10, 1, new_storage(), true); raft.become_follower(1, INVALID_ID); @@ -4185,6 +4295,7 @@ fn test_prevote_with_split_vote() { // ensure that after a node become pre-candidate, it will checkQuorum correctly. #[test] fn test_prevote_with_check_quorum() { + let _ = env_logger::try_init(); let bootstrap = |id| { let mut cfg = new_test_config(id, vec![1, 2, 3], 10, 1); cfg.pre_vote = true; diff --git a/tests/cases/test_raft_flow_control.rs b/tests/cases/test_raft_flow_control.rs index 316445a3d..f141ca2a1 100644 --- a/tests/cases/test_raft_flow_control.rs +++ b/tests/cases/test_raft_flow_control.rs @@ -27,12 +27,14 @@ use super::test_raft::*; use raft::eraftpb::*; +use env_logger; // test_msg_app_flow_control_full ensures: // 1. msgApp can fill the sending window until full // 2. when the window is full, no more msgApp can be sent. #[test] fn test_msg_app_flow_control_full() { + let _ = env_logger::try_init(); let mut r = new_test_raft(1, vec![1, 2], 5, 1, new_storage()); r.become_candidate(); r.become_leader(); @@ -69,6 +71,7 @@ fn test_msg_app_flow_control_full() { // 2. out-of-dated msgAppResp has no effect on the sliding window. #[test] fn test_msg_app_flow_control_move_forward() { + let _ = env_logger::try_init(); let mut r = new_test_raft(1, vec![1, 2], 5, 1, new_storage()); r.become_candidate(); r.become_leader(); @@ -122,6 +125,7 @@ fn test_msg_app_flow_control_move_forward() { // frees one slot if the window is full. #[test] fn test_msg_app_flow_control_recv_heartbeat() { + let _ = env_logger::try_init(); let mut r = new_test_raft(1, vec![1, 2], 5, 1, new_storage()); r.become_candidate(); r.become_leader(); diff --git a/tests/cases/test_raft_paper.rs b/tests/cases/test_raft_paper.rs index f8325b257..24d0887d3 100644 --- a/tests/cases/test_raft_paper.rs +++ b/tests/cases/test_raft_paper.rs @@ -30,6 +30,7 @@ use protobuf::RepeatedField; use raft::eraftpb::*; use raft::storage::MemStorage; use raft::*; +use env_logger; pub fn hard_state(t: u64, c: u64, v: u64) -> HardState { let mut hs = HardState::new(); @@ -71,16 +72,19 @@ fn accept_and_reply(m: &Message) -> Message { #[test] fn test_follower_update_term_from_message() { + let _ = env_logger::try_init(); test_update_term_from_message(StateRole::Follower); } #[test] fn test_candidate_update_term_from_message() { + let _ = env_logger::try_init(); test_update_term_from_message(StateRole::Candidate); } #[test] fn test_leader_update_term_from_message() { + let _ = env_logger::try_init(); test_update_term_from_message(StateRole::Leader); } @@ -115,6 +119,7 @@ fn test_update_term_from_message(state: StateRole) { // Reference: section 5.1 #[test] fn test_reject_stale_term_message() { + let _ = env_logger::try_init(); let mut r = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage()); let panic_before_step_state = Box::new(|_: &Message| panic!("before step state function hook called unexpectedly")); @@ -130,6 +135,7 @@ fn test_reject_stale_term_message() { // Reference: section 5.2 #[test] fn test_start_as_follower() { + let _ = env_logger::try_init(); let r = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage()); assert_eq!(r.state, StateRole::Follower); } @@ -140,6 +146,7 @@ fn test_start_as_follower() { // Reference: section 5.2 #[test] fn test_leader_bcast_beat() { + let _ = env_logger::try_init(); // heartbeat interval let hi = 1; let mut r = new_test_raft(1, vec![1, 2, 3], 10, hi, new_storage()); @@ -169,11 +176,13 @@ fn test_leader_bcast_beat() { #[test] fn test_follower_start_election() { + let _ = env_logger::try_init(); test_nonleader_start_election(StateRole::Follower); } #[test] fn test_candidate_start_new_election() { + let _ = env_logger::try_init(); test_nonleader_start_election(StateRole::Candidate); } @@ -225,6 +234,7 @@ fn test_nonleader_start_election(state: StateRole) { // Reference: section 5.2 #[test] fn test_leader_election_in_one_round_rpc() { + let _ = env_logger::try_init(); let mut tests = vec![ // win the election when receiving votes from a majority of the servers (1, map!(), StateRole::Leader), @@ -281,6 +291,7 @@ fn test_leader_election_in_one_round_rpc() { // Reference: section 5.2 #[test] fn test_follower_vote() { + let _ = env_logger::try_init(); let mut tests = vec![ (INVALID_ID, 1, false), (INVALID_ID, 2, false), @@ -316,6 +327,7 @@ fn test_follower_vote() { // Reference: section 5.2 #[test] fn test_candidate_fallback() { + let _ = env_logger::try_init(); let new_message_ext = |f, to, term| { let mut m = new_message(f, to, MessageType::MsgAppend, 0); m.set_term(term); @@ -346,11 +358,13 @@ fn test_candidate_fallback() { #[test] fn test_follower_election_timeout_randomized() { + let _ = env_logger::try_init(); test_non_leader_election_timeout_randomized(StateRole::Follower); } #[test] fn test_candidate_election_timeout_randomized() { + let _ = env_logger::try_init(); test_non_leader_election_timeout_randomized(StateRole::Candidate); } @@ -385,11 +399,13 @@ fn test_non_leader_election_timeout_randomized(state: StateRole) { #[test] fn test_follower_election_timeout_nonconflict() { + let _ = env_logger::try_init(); test_nonleaders_election_timeout_nonconfict(StateRole::Follower); } #[test] fn test_acandidates_election_timeout_nonconf() { + let _ = env_logger::try_init(); test_nonleaders_election_timeout_nonconfict(StateRole::Candidate); } @@ -444,6 +460,7 @@ fn test_nonleaders_election_timeout_nonconfict(state: StateRole) { // Reference: section 5.3 #[test] fn test_leader_start_replication() { + let _ = env_logger::try_init(); let s = new_storage(); let mut r = new_test_raft(1, vec![1, 2, 3], 10, 1, s.clone()); r.become_candidate(); @@ -485,6 +502,7 @@ fn test_leader_start_replication() { // Reference: section 5.3 #[test] fn test_leader_commit_entry() { + let _ = env_logger::try_init(); let s = new_storage(); let mut r = new_test_raft(1, vec![1, 2, 3], 10, 1, s.clone()); r.become_candidate(); @@ -515,6 +533,7 @@ fn test_leader_commit_entry() { // Reference: section 5.3 #[test] fn test_leader_acknowledge_commit() { + let _ = env_logger::try_init(); let mut tests = vec![ (1, map!(), true), (3, map!(), false), @@ -556,6 +575,7 @@ fn test_leader_acknowledge_commit() { // Reference: section 5.3 #[test] fn test_leader_commit_preceding_entries() { + let _ = env_logger::try_init(); let mut tests = vec![ vec![], vec![empty_entry(2, 1)], @@ -595,6 +615,7 @@ fn test_leader_commit_preceding_entries() { // Reference: section 5.3 #[test] fn test_follower_commit_entry() { + let _ = env_logger::try_init(); let mut tests = vec![ (vec![new_entry(1, 1, SOME_DATA)], 1), ( @@ -651,6 +672,7 @@ fn test_follower_commit_entry() { // Reference: section 5.3 #[test] fn test_follower_check_msg_append() { + let _ = env_logger::try_init(); let ents = vec![empty_entry(1, 1), empty_entry(2, 2)]; let mut tests = vec![ // match with committed entries @@ -710,6 +732,7 @@ fn test_follower_check_msg_append() { // Reference: section 5.3 #[test] fn test_follower_append_entries() { + let _ = env_logger::try_init(); let mut tests = vec![ ( 2, @@ -776,6 +799,7 @@ fn test_follower_append_entries() { // Reference: section 5.3, figure 7 #[test] fn test_leader_sync_follower_log() { + let _ = env_logger::try_init(); let ents = vec![ empty_entry(0, 0), empty_entry(1, 1), @@ -904,6 +928,7 @@ fn test_leader_sync_follower_log() { // Reference: section 5.4.1 #[test] fn test_vote_request() { + let _ = env_logger::try_init(); let mut tests = vec![ (vec![empty_entry(1, 1)], 2), (vec![empty_entry(1, 1), empty_entry(2, 2)], 3), @@ -966,6 +991,7 @@ fn test_vote_request() { // Reference: section 5.4.1 #[test] fn test_voter() { + let _ = env_logger::try_init(); let mut tests = vec![ // same logterm (vec![empty_entry(1, 1)], 1, 1, false), @@ -1019,6 +1045,7 @@ fn test_voter() { // Reference: section 5.4.2 #[test] fn test_leader_only_commits_log_from_current_term() { + let _ = env_logger::try_init(); let ents = vec![empty_entry(1, 1), empty_entry(2, 2)]; let mut tests = vec![ // do not commit log entries in previous terms diff --git a/tests/cases/test_raft_snap.rs b/tests/cases/test_raft_snap.rs index bcc5a947b..a3064d281 100644 --- a/tests/cases/test_raft_snap.rs +++ b/tests/cases/test_raft_snap.rs @@ -27,6 +27,7 @@ use super::test_raft::*; use raft::eraftpb::*; +use env_logger; fn testing_snap() -> Snapshot { new_snapshot(11, 11, vec![1, 2]) @@ -34,6 +35,7 @@ fn testing_snap() -> Snapshot { #[test] fn test_sending_snapshot_set_pending_snapshot() { + let _ = env_logger::try_init(); let mut sm = new_test_raft(1, vec![1], 10, 1, new_storage()); sm.restore(testing_snap()); @@ -53,6 +55,7 @@ fn test_sending_snapshot_set_pending_snapshot() { #[test] fn test_pending_snapshot_pause_replication() { + let _ = env_logger::try_init(); let mut sm = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); sm.restore(testing_snap()); @@ -68,6 +71,7 @@ fn test_pending_snapshot_pause_replication() { #[test] fn test_snapshot_failure() { + let _ = env_logger::try_init(); let mut sm = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); sm.restore(testing_snap()); @@ -87,6 +91,7 @@ fn test_snapshot_failure() { #[test] fn test_snapshot_succeed() { + let _ = env_logger::try_init(); let mut sm = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); sm.restore(testing_snap()); @@ -106,6 +111,7 @@ fn test_snapshot_succeed() { #[test] fn test_snapshot_abort() { + let _ = env_logger::try_init(); let mut sm = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); sm.restore(testing_snap()); diff --git a/tests/cases/test_raw_node.rs b/tests/cases/test_raw_node.rs index c74083b2f..751d6e643 100644 --- a/tests/cases/test_raw_node.rs +++ b/tests/cases/test_raw_node.rs @@ -32,6 +32,7 @@ use raft::eraftpb::*; use raft::storage::MemStorage; use raft::*; use std::sync::*; +use env_logger; fn new_peer(id: u64) -> Peer { Peer { @@ -93,6 +94,7 @@ fn new_raw_node( // test_raw_node_step ensures that RawNode.Step ignore local message. #[test] fn test_raw_node_step() { + let _ = env_logger::try_init(); for msg_t in MessageType::values() { let mut raw_node = new_raw_node(1, vec![], 10, 1, new_storage(), vec![new_peer(1)]); let res = raw_node.step(new_message(0, 0, *msg_t, 0)); @@ -113,6 +115,7 @@ fn test_raw_node_step() { // forward to the new leader and 'send' method does not attach its term #[test] fn test_raw_node_read_index_to_old_leader() { + let _ = env_logger::try_init(); let r1 = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage()); let r2 = new_test_raft(2, vec![1, 2, 3], 10, 1, new_storage()); let r3 = new_test_raft(3, vec![1, 2, 3], 10, 1, new_storage()); @@ -174,6 +177,7 @@ fn test_raw_node_read_index_to_old_leader() { // RawNode.propose_conf_change send the given proposal and ConfChange to the underlying raft. #[test] fn test_raw_node_propose_and_conf_change() { + let _ = env_logger::try_init(); let s = new_storage(); let mut raw_node = new_raw_node(1, vec![], 10, 1, s.clone(), vec![new_peer(1)]); let rd = raw_node.ready(); @@ -217,6 +221,7 @@ fn test_raw_node_propose_and_conf_change() { // not affect the later propose to add new node. #[test] fn test_raw_node_propose_add_duplicate_node() { + let _ = env_logger::try_init(); let s = new_storage(); let mut raw_node = new_raw_node(1, vec![], 10, 1, s.clone(), vec![new_peer(1)]); let rd = raw_node.ready(); @@ -270,6 +275,7 @@ fn test_raw_node_propose_add_duplicate_node() { #[test] fn test_raw_node_propose_add_learner_node() { + let _ = env_logger::try_init(); let s = new_storage(); let mut raw_node = new_raw_node(1, vec![], 10, 1, s.clone(), vec![new_peer(1)]); let rd = raw_node.ready(); @@ -310,6 +316,7 @@ fn test_raw_node_propose_add_learner_node() { // to the underlying raft. It also ensures that ReadState can be read out. #[test] fn test_raw_node_read_index() { + let _ = env_logger::try_init(); let a = Arc::new(RwLock::new(Vec::new())); let b = Arc::clone(&a); let before_step_state = Box::new(move |m: &Message| { @@ -364,6 +371,7 @@ fn test_raw_node_read_index() { // proposals. #[test] fn test_raw_node_start() { + let _ = env_logger::try_init(); let cc = conf_change(ConfChangeType::AddNode, 1); let ccdata = protobuf::Message::write_to_bytes(&cc).unwrap(); let wants = vec![ @@ -420,6 +428,7 @@ fn test_raw_node_start() { #[test] fn test_raw_node_restart() { + let _ = env_logger::try_init(); let entries = vec![empty_entry(1, 1), new_entry(1, 2, Some("foo"))]; let st = hard_state(1, 1, 0); @@ -437,6 +446,7 @@ fn test_raw_node_restart() { #[test] fn test_raw_node_restart_from_snapshot() { + let _ = env_logger::try_init(); let snap = new_snapshot(2, 1, vec![1, 2]); let entries = vec![new_entry(1, 3, Some("foo"))]; let st = hard_state(1, 3, 0); @@ -458,6 +468,7 @@ fn test_raw_node_restart_from_snapshot() { // when skip_bcast_commit is true. #[test] fn test_skip_bcast_commit() { + let _ = env_logger::try_init(); let mut config = new_test_config(1, vec![1, 2, 3], 10, 1); config.skip_bcast_commit = true; let r1 = new_test_raft_with_config(&config, new_storage()); diff --git a/tests/tests.rs b/tests/tests.rs index 47d427152..d14491709 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -20,6 +20,7 @@ extern crate log; extern crate protobuf; extern crate raft; extern crate rand; +extern crate env_logger; /// Get the count of macro's arguments. ///