Skip to content

Commit

Permalink
chore: move test_disable_proposal_forwarding to test_raw_node.rs
Browse files Browse the repository at this point in the history
Signed-off-by: Dat Tien Nguyen <phongtomfapp@gmail.com>
  • Loading branch information
datbeohbbh committed Oct 9, 2024
1 parent 4bc761c commit 9d3aa0d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 71 deletions.
71 changes: 0 additions & 71 deletions harness/tests/integration_cases/test_raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
71 changes: 71 additions & 0 deletions harness/tests/integration_cases/test_raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9d3aa0d

Please sign in to comment.