From f4d694693c62378db4740d152ae3679b2954e282 Mon Sep 17 00:00:00 2001 From: Zeling Feng Date: Wed, 17 Feb 2021 22:05:05 -0800 Subject: Deflake tcp_network_unreachable test Previously, we make two connect attempts. If the first attempt is still on going when the second attempt is made, the test will fail. This change deflakes the situation by not making the second attempt, instead, we poll for the first attempt's completion and read the errno from SO_ERROR. PiperOrigin-RevId: 358104769 --- test/packetimpact/testbench/dut.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/packetimpact/testbench/dut.go') diff --git a/test/packetimpact/testbench/dut.go b/test/packetimpact/testbench/dut.go index aedcf6013..81634b5f4 100644 --- a/test/packetimpact/testbench/dut.go +++ b/test/packetimpact/testbench/dut.go @@ -486,6 +486,23 @@ func (dut *DUT) ListenWithErrno(ctx context.Context, t *testing.T, sockfd, backl return resp.GetRet(), syscall.Errno(resp.GetErrno_()) } +// PollOne calls poll on the DUT and asserts that the expected event must be +// signaled on the given fd within the given timeout. +func (dut *DUT) PollOne(t *testing.T, fd int32, events int16, timeout time.Duration) { + t.Helper() + + pfds := dut.Poll(t, []unix.PollFd{{Fd: fd, Events: events}}, timeout) + if n := len(pfds); n != 1 { + t.Fatalf("Poll returned %d ready file descriptors, expected 1", n) + } + if readyFd := pfds[0].Fd; readyFd != fd { + t.Fatalf("Poll returned an fd %d that was not requested (%d)", readyFd, fd) + } + if got, want := pfds[0].Revents, int16(events); got&want == 0 { + t.Fatalf("Poll returned no events in our interest, got: %#b, want: %#b", got, want) + } +} + // Poll calls poll on the DUT and causes a fatal test failure if it doesn't // succeed. If more control over error handling is needed, use PollWithErrno. // Only pollfds with non-empty revents are returned, the only way to tie the -- cgit v1.2.3