Skip to content

Commit

Permalink
Add UDP test using sending empty data
Browse files Browse the repository at this point in the history
Other discussion: nodejs/node#30030

Signed-off-by: Kevin Leimkuhler <kevin@kleimkuhler.com>
  • Loading branch information
kleimkuhler authored and Thomasdezeeuw committed Nov 6, 2020
1 parent 13e82ce commit 7d413c8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/udp_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,39 @@ const ID1: Token = Token(2);
const ID2: Token = Token(3);
const ID3: Token = Token(4);

#[test]
fn empty_datagram() {
const EMPTY: &[u8] = b"";

let (mut poll, mut events) = init_with_poll();
let mut s1 = UdpSocket::bind(any_local_address()).unwrap();
let mut s2 = UdpSocket::bind(any_local_address()).unwrap();

poll.registry()
.register(&mut s1, ID1, Interest::WRITABLE)
.unwrap();
poll.registry()
.register(&mut s2, ID2, Interest::READABLE)
.unwrap();

expect_events(
&mut poll,
&mut events,
vec![ExpectEvent::new(ID1, Interest::WRITABLE)],
);

checked_write!(s1.send_to(EMPTY, s2.local_addr().unwrap()));

let mut buf = [0; 10];

expect_events(
&mut poll,
&mut events,
vec![ExpectEvent::new(ID2, Interest::READABLE)],
);
expect_read!(s2.recv_from(&mut buf), EMPTY, s1.local_addr().unwrap());
}

#[test]
fn is_send_and_sync() {
assert_send::<UdpSocket>();
Expand Down

0 comments on commit 7d413c8

Please sign in to comment.