diff options
author | Zeling Feng <zeling@google.com> | 2021-02-17 22:05:05 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-02-17 22:07:06 -0800 |
commit | f4d694693c62378db4740d152ae3679b2954e282 (patch) | |
tree | b1c7b1edbcec34d72f9d6a4e7d0a679548ef94a2 /test/packetimpact/testbench/dut.go | |
parent | dea894238bf404523a6c78819e242e0fb727e225 (diff) |
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
Diffstat (limited to 'test/packetimpact/testbench/dut.go')
-rw-r--r-- | test/packetimpact/testbench/dut.go | 17 |
1 files changed, 17 insertions, 0 deletions
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 |