From 438c84460d6ed2dc085c407b05f15eed9e97d608 Mon Sep 17 00:00:00 2001 From: Nick Brown Date: Thu, 17 Mar 2022 16:47:32 -0700 Subject: [PATCH] Poll for POLLERR before validating ICMP error ...since ICMP errors are returned asynchronously. This also matches the behavior of existing tests. PiperOrigin-RevId: 435484650 --- test/syscalls/linux/udp_socket.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/syscalls/linux/udp_socket.cc b/test/syscalls/linux/udp_socket.cc index f126467c0..a870efa53 100644 --- a/test/syscalls/linux/udp_socket.cc +++ b/test/syscalls/linux/udp_socket.cc @@ -382,6 +382,11 @@ TEST_P(UdpSocketTest, ConnectWriteToInvalidPort) { ASSERT_THAT(sendto(sock_.get(), buf, sizeof(buf), 0, addr, addrlen_), SyscallSucceedsWithValue(sizeof(buf))); + // Poll to make sure we get the ICMP error back. + constexpr int kTimeout = 1000; + struct pollfd pfd = {sock_.get(), POLLERR, 0}; + ASSERT_THAT(RetryEINTR(poll)(&pfd, 1, kTimeout), SyscallSucceedsWithValue(1)); + // Now verify that we got an ICMP error back of ECONNREFUSED. int err; socklen_t optlen = sizeof(err);