Skip to content

Commit

Permalink
clippy and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-jfisher committed Mar 24, 2023
1 parent a210a02 commit 9806722
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ pub(crate) mod private {

/// Check if a payload length is small enough to fit in a message body.
pub fn check_payload_too_large(body_len: usize, max_len: usize) -> Result<(), InnerError> {
if body_len <= max_len as usize {
if body_len <= max_len {
Ok(())
} else {
Err(InnerError::PayloadTooLarge { body_len, max_len })
Expand Down
25 changes: 25 additions & 0 deletions src/peer_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,28 @@ impl<Body> std::fmt::Debug for PeerWriteHandle<Body> {
.finish_non_exhaustive()
}
}

#[cfg(test)]
mod test {
use fizyr_rpc::UnixSeqpacketTransport;

use assert2::assert;
use assert2::let_assert;
use tokio_seqpacket::UnixSeqpacket;

#[tokio::test]
async fn test_same_peer() {
let_assert!(Ok((peer_a, peer_b)) = UnixSeqpacket::pair());
let transport_a = UnixSeqpacketTransport::new(peer_a, Default::default());
let peer_handle = fizyr_rpc::UnixSeqpacketPeer::spawn(transport_a);

let (_, write_handle_a) = peer_handle.split();
let duplicate = write_handle_a.clone();
assert!(write_handle_a.same_peer(&duplicate));

let transport_b = UnixSeqpacketTransport::new(peer_b, Default::default());
let peer_handle = fizyr_rpc::UnixSeqpacketPeer::spawn(transport_b);
let (_, write_handle_b) = peer_handle.split();
assert!(!write_handle_a.same_peer(&write_handle_b));
}
}
2 changes: 1 addition & 1 deletion src/transport/stream/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ where
.map_err(TransportError::new_fatal)?;

// Check body length and create body buffer.
let body_len = length - crate::HEADER_LEN as u32;
let body_len = length - crate::HEADER_LEN;
check_payload_too_large(body_len as usize, this.max_body_len as usize)
.map_err(TransportError::new_fatal)?;
this.body_buffer = vec![0; body_len as usize];
Expand Down

0 comments on commit 9806722

Please sign in to comment.