Poll for POLLERR before validating ICMP error

...since ICMP errors are returned asynchronously. This also matches the
behavior of existing tests.

PiperOrigin-RevId: 435484650
This commit is contained in:
Nick Brown
2022-03-17 16:50:09 -07:00
committed by gVisor bot
parent bf86207401
commit 438c84460d
+5
View File
@@ -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);