From ebd7085bc10481341d8aa2a56a969a5bfeec76be Mon Sep 17 00:00:00 2001 From: Kevin Leimkuhler Date: Mon, 20 Jan 2020 17:43:41 -0800 Subject: [PATCH] Other discussion: https://github.com/nodejs/node/issues/30030 Signed-off-by: Kevin Leimkuhler --- tests/udp_socket.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/udp_socket.rs b/tests/udp_socket.rs index 874654d33e..20bfb5c4c2 100644 --- a/tests/udp_socket.rs +++ b/tests/udp_socket.rs @@ -28,6 +28,43 @@ 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]; + + // Fails on MacOS because of unexpected (bug?) kqueue behavior. + // + // Other discussion: https://github.com/nodejs/node/issues/30030 + expect_events( + &mut poll, + &mut events, + vec![ExpectEvent::new(ID2, Interest::READABLE)], + ); + // This also fails. + expect_read!(s2.recv_from(&mut buf), EMPTY, s1.local_addr().unwrap()); +} + #[test] fn is_send_and_sync() { assert_send::();