Skip to content

Commit

Permalink
fix: remove display trait for StreamMessage and fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guy-starkware committed Sep 24, 2024
1 parent df23102 commit e7d281f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 36 deletions.
13 changes: 0 additions & 13 deletions crates/papyrus_protobuf/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ pub struct StreamMessage<T: Into<Vec<u8>> + TryFrom<Vec<u8>, Error = ProtobufCon
pub fin: bool,
}

impl<T: Clone + Into<Vec<u8>> + TryFrom<Vec<u8>, Error = ProtobufConversionError>> std::fmt::Display
for StreamMessage<T>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let message: Vec<u8> = self.message.clone().into();
write!(
f,
"StreamMessage {{ message: {:?}, stream_id: {}, message_id: {}, fin: {} }}",
message, self.stream_id, self.message_id, self.fin
)
}
}

// TODO(Guy): Remove after implementing broadcast streams.
#[allow(missing_docs)]
pub struct ProposalWrapper(pub Proposal);
Expand Down
7 changes: 2 additions & 5 deletions crates/sequencing/papyrus_consensus/src/stream_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,8 @@ impl<T: Clone + Into<Vec<u8>> + TryFrom<Vec<u8>, Error = ProtobufConversionError
if data.message_buffer.contains_key(&message_id) {
// TODO(guyn): replace panics with more graceful error handling
panic!(
"Two messages with the same message_id in buffer! stream_id: {}, old message: {}, \
new message: {}",
stream_id,
data.message_buffer.get(&message_id).unwrap(),
message
"Two messages with the same message_id in buffer! stream_id: {}, message_id: {}",
stream_id, message_id
);
} else {
data.message_buffer.insert(message_id, message);
Expand Down
18 changes: 0 additions & 18 deletions crates/sequencing/papyrus_consensus/src/stream_handler_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,4 @@ mod tests {

join_handle.await.expect("Task should succeed");
}

#[tokio::test]
#[should_panic]
async fn test_stream_handler_max_streams_fails() {
let (mut h, mut tx_input, _rx_output) = setup_test();
h.config.max_num_streams = Some(10);
// skip the first message, so the messages all get buffered
for i in 0..11 {
tx_input.try_send(make_random_message(i, 1, false)).expect("Send should succeed");
}

// this should panic since there are too many streams at the same time
let join_handle = tokio::spawn(async move {
let _ = tokio::time::timeout(Duration::from_millis(100), h.listen()).await;
});

join_handle.await.expect("Task should succeed");
}
}

0 comments on commit e7d281f

Please sign in to comment.