Skip to content

Commit

Permalink
tests: async read
Browse files Browse the repository at this point in the history
  • Loading branch information
discord9 committed Sep 18, 2024
1 parent b3d20d7 commit 52f672a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions mysql/src/packet_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ mod test {
buf.freeze()
}

#[test]
fn test_various_packet_size() {
#[tokio::test]
async fn test_various_packet_size() {
// test for off by one, and off by header size(3 bytes for length and 1 for seq num)
let testcases = [
0,
Expand Down Expand Up @@ -446,5 +446,20 @@ mod test {
}
assert_eq!(total_size, input_size);
}
for input_size in testcases {
let large_data = bytes::Bytes::from(vec![0; input_size]);
let packet = mock_packet(large_data, 0);
let mut reader = PacketReader::new(packet.as_ref());
let mut last_seq = 0;
let mut total_size = 0;
while let Some((seq, packet)) = reader.next_async().await.unwrap() {
if seq != 0 {
assert!(seq > last_seq);
}
total_size += packet.len();
last_seq = seq;
}
assert_eq!(total_size, input_size);
}
}
}

0 comments on commit 52f672a

Please sign in to comment.