Skip to content

Commit ebd7085

Browse files
committed
Other discussion: nodejs/node#30030
Signed-off-by: Kevin Leimkuhler <[email protected]>
1 parent 92b03bb commit ebd7085

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/udp_socket.rs

+37
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,43 @@ const ID1: Token = Token(2);
2828
const ID2: Token = Token(3);
2929
const ID3: Token = Token(4);
3030

31+
#[test]
32+
fn empty_datagram() {
33+
const EMPTY: &[u8] = b"";
34+
35+
let (mut poll, mut events) = init_with_poll();
36+
let mut s1 = UdpSocket::bind(any_local_address()).unwrap();
37+
let mut s2 = UdpSocket::bind(any_local_address()).unwrap();
38+
39+
poll.registry()
40+
.register(&mut s1, ID1, Interest::WRITABLE)
41+
.unwrap();
42+
poll.registry()
43+
.register(&mut s2, ID2, Interest::READABLE)
44+
.unwrap();
45+
46+
expect_events(
47+
&mut poll,
48+
&mut events,
49+
vec![ExpectEvent::new(ID1, Interest::WRITABLE)],
50+
);
51+
52+
checked_write!(s1.send_to(EMPTY, s2.local_addr().unwrap()));
53+
54+
let mut buf = [0; 10];
55+
56+
// Fails on MacOS because of unexpected (bug?) kqueue behavior.
57+
//
58+
// Other discussion: https://github.com/nodejs/node/issues/30030
59+
expect_events(
60+
&mut poll,
61+
&mut events,
62+
vec![ExpectEvent::new(ID2, Interest::READABLE)],
63+
);
64+
// This also fails.
65+
expect_read!(s2.recv_from(&mut buf), EMPTY, s1.local_addr().unwrap());
66+
}
67+
3168
#[test]
3269
fn is_send_and_sync() {
3370
assert_send::<UdpSocket>();

0 commit comments

Comments
 (0)