Skip to content

Commit

Permalink
[consensus] add unit test for the echo timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
zekun000 committed Aug 1, 2022
1 parent b7d9092 commit f5f0e6d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
46 changes: 46 additions & 0 deletions consensus/src/round_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,3 +1022,49 @@ fn safety_rules_crash() {
node.next_proposal().await;
});
}

#[test]
fn echo_timeout() {
let mut runtime = consensus_runtime();
let mut playground = NetworkPlayground::new(runtime.handle().clone());
let mut nodes = NodeSetup::create_nodes(&mut playground, runtime.handle().clone(), 4);
runtime.spawn(playground.start());
timed_block_on(&mut runtime, async {
// clear the message queue
for node in &mut nodes {
node.next_proposal().await;
}
// timeout 3 nodes
for node in &mut nodes[1..] {
node.round_manager
.process_local_timeout(1)
.await
.unwrap_err();
}
let node_0 = &mut nodes[0];
// node 0 doesn't timeout and should echo the timeout after 2 timeout message
for i in 0..3 {
let timeout_vote = node_0.next_vote().await;
let result = node_0.round_manager.process_vote_msg(timeout_vote).await;
// first and third message should not timeout
if i == 0 || i == 2 {
assert!(result.is_ok());
}
if i == 1 {
// timeout is an Error
assert!(result.is_err());
}
}

let node_1 = &mut nodes[1];
// it receives 4 timeout messages (1 from each) and doesn't echo since it already timeout
for _ in 0..4 {
let timeout_vote = node_1.next_vote().await;
node_1
.round_manager
.process_vote_msg(timeout_vote)
.await
.unwrap();
}
});
}
6 changes: 3 additions & 3 deletions consensus/src/test_utils/mock_payload_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ use rand::Rng;

pub struct MockPayloadManager {
// used non-mocked TxnManager to test interaction with shared mempool
quorum_store_client: Option<QuorumStoreClient>,
_quorum_store_client: Option<QuorumStoreClient>,
}

impl MockPayloadManager {
pub fn new(consensus_to_quorum_store_sender: Option<mpsc::Sender<ConsensusRequest>>) -> Self {
let quorum_store_client =
consensus_to_quorum_store_sender.map(|s| QuorumStoreClient::new(s, 1, 1));
Self {
quorum_store_client,
_quorum_store_client: quorum_store_client,
}
}
}

// mock transaction status on the fly
fn mock_transaction_status(count: usize) -> Vec<TransactionStatus> {
fn _mock_transaction_status(count: usize) -> Vec<TransactionStatus> {
let mut statuses = vec![];
// generate count + 1 status to mock the block metadata txn in mempool proxy
for _ in 0..=count {
Expand Down

0 comments on commit f5f0e6d

Please sign in to comment.