From 9d3aa0d837590391c8cc61b76ab6dcf6eceeae6c Mon Sep 17 00:00:00 2001 From: Dat Tien Nguyen Date: Wed, 9 Oct 2024 13:38:42 +0700 Subject: [PATCH] chore: move test_disable_proposal_forwarding to test_raw_node.rs Signed-off-by: Dat Tien Nguyen --- harness/tests/integration_cases/test_raft.rs | 71 ------------------- .../tests/integration_cases/test_raw_node.rs | 71 +++++++++++++++++++ 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/harness/tests/integration_cases/test_raft.rs b/harness/tests/integration_cases/test_raft.rs index 04cfbcdf..a62266d2 100644 --- a/harness/tests/integration_cases/test_raft.rs +++ b/harness/tests/integration_cases/test_raft.rs @@ -5851,74 +5851,3 @@ fn test_switching_check_quorum() { } assert_eq!(sm.state, StateRole::Leader); } - -#[test] -fn test_disable_proposal_forwarding() { - let l = default_logger(); - - let n1 = new_test_raft_with_config( - &Config { - id: 1, - heartbeat_tick: 1, - election_tick: 10, - disable_proposal_forwarding: false, - ..Default::default() - }, - MemStorage::new_with_conf_state((vec![1, 2, 3], vec![])), - &l, - ); - - let n2 = new_test_raft_with_config( - &Config { - id: 2, - heartbeat_tick: 1, - election_tick: 10, - disable_proposal_forwarding: false, - ..Default::default() - }, - MemStorage::new_with_conf_state((vec![1, 2, 3], vec![])), - &l, - ); - - let n3 = new_test_raft_with_config( - &Config { - id: 3, - heartbeat_tick: 1, - election_tick: 10, - disable_proposal_forwarding: true, - ..Default::default() - }, - MemStorage::new_with_conf_state((vec![1, 2, 3], vec![])), - &l, - ); - - let mut network = Network::new(vec![Some(n1), Some(n2), Some(n3)], &l); - - // node 1 starts campaign to become leader. - network.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); - - // send proposal to n2(follower) where DisableProposalForwarding is false - assert_eq!( - network - .peers - .get_mut(&2) - .unwrap() - .step(new_message(2, 2, MessageType::MsgPropose, 1)), - Ok(()) - ); - - // verify n2(follower) does forward the proposal when DisableProposalForwarding is false - assert_eq!(network.peers.get(&2).unwrap().msgs.len(), 1); - - // send proposal to n3(follower) where DisableProposalForwarding is true - assert_eq!( - network - .peers - .get_mut(&3) - .unwrap() - .step(new_message(3, 3, MessageType::MsgPropose, 1)), - Err(Error::ProposalDropped) - ); - - assert_eq!(network.peers.get(&3).unwrap().msgs.is_empty(), true); -} diff --git a/harness/tests/integration_cases/test_raw_node.rs b/harness/tests/integration_cases/test_raw_node.rs index 5cea3f55..5b7c7324 100644 --- a/harness/tests/integration_cases/test_raw_node.rs +++ b/harness/tests/integration_cases/test_raw_node.rs @@ -1876,6 +1876,77 @@ fn test_committed_entries_pagination_after_restart() { } } +#[test] +fn test_disable_proposal_forwarding() { + let l = default_logger(); + + let n1 = new_test_raft_with_config( + &Config { + id: 1, + heartbeat_tick: 1, + election_tick: 10, + disable_proposal_forwarding: false, + ..Default::default() + }, + MemStorage::new_with_conf_state((vec![1, 2, 3], vec![])), + &l, + ); + + let n2 = new_test_raft_with_config( + &Config { + id: 2, + heartbeat_tick: 1, + election_tick: 10, + disable_proposal_forwarding: false, + ..Default::default() + }, + MemStorage::new_with_conf_state((vec![1, 2, 3], vec![])), + &l, + ); + + let n3 = new_test_raft_with_config( + &Config { + id: 3, + heartbeat_tick: 1, + election_tick: 10, + disable_proposal_forwarding: true, + ..Default::default() + }, + MemStorage::new_with_conf_state((vec![1, 2, 3], vec![])), + &l, + ); + + let mut network = Network::new(vec![Some(n1), Some(n2), Some(n3)], &l); + + // node 1 starts campaign to become leader. + network.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); + + // send proposal to n2(follower) where DisableProposalForwarding is false + assert_eq!( + network + .peers + .get_mut(&2) + .unwrap() + .step(new_message(2, 2, MessageType::MsgPropose, 1)), + Ok(()) + ); + + // verify n2(follower) does forward the proposal when DisableProposalForwarding is false + assert_eq!(network.peers.get(&2).unwrap().msgs.len(), 1); + + // send proposal to n3(follower) where DisableProposalForwarding is true + assert_eq!( + network + .peers + .get_mut(&3) + .unwrap() + .step(new_message(3, 3, MessageType::MsgPropose, 1)), + Err(Error::ProposalDropped) + ); + + assert_eq!(network.peers.get(&3).unwrap().msgs.is_empty(), true); +} + #[derive(Default)] struct IgnoreSizeHintMemStorage { inner: MemStorage,