Use cmp.Diff for tcpip.Error comparison

PiperOrigin-RevId: 372021039
This commit is contained in:
Mithun Iyer 2021-05-04 16:40:17 -07:00 committed by gVisor bot
parent e00bd82816
commit 682415b6d0
2 changed files with 66 additions and 65 deletions

View File

@ -19,6 +19,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/google/go-cmp/cmp"
"gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/checker" "gvisor.dev/gvisor/pkg/tcpip/checker"
"gvisor.dev/gvisor/pkg/tcpip/header" "gvisor.dev/gvisor/pkg/tcpip/header"
@ -37,8 +38,8 @@ func TestV4MappedConnectOnV6Only(t *testing.T) {
// Start connection attempt, it must fail. // Start connection attempt, it must fail.
err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestV4MappedAddr, Port: context.TestPort}) err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestV4MappedAddr, Port: context.TestPort})
if _, ok := err.(*tcpip.ErrNoRoute); !ok { if d := cmp.Diff(&tcpip.ErrNoRoute{}, err); d != "" {
t.Fatalf("Unexpected return value from Connect: %v", err) t.Fatalf("c.EP.Connect(...) mismatch (-want +got):\n%s", d)
} }
} }
@ -49,8 +50,8 @@ func testV4Connect(t *testing.T, c *context.Context, checkers ...checker.Network
defer c.WQ.EventUnregister(&we) defer c.WQ.EventUnregister(&we)
err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestV4MappedAddr, Port: context.TestPort}) err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestV4MappedAddr, Port: context.TestPort})
if _, ok := err.(*tcpip.ErrConnectStarted); !ok { if d := cmp.Diff(&tcpip.ErrConnectStarted{}, err); d != "" {
t.Fatalf("Unexpected return value from Connect: %v", err) t.Fatalf("c.EP.Connect(...) mismatch (-want +got):\n%s", d)
} }
// Receive SYN packet. // Receive SYN packet.
@ -156,8 +157,8 @@ func testV6Connect(t *testing.T, c *context.Context, checkers ...checker.Network
defer c.WQ.EventUnregister(&we) defer c.WQ.EventUnregister(&we)
err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestV6Addr, Port: context.TestPort}) err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestV6Addr, Port: context.TestPort})
if _, ok := err.(*tcpip.ErrConnectStarted); !ok { if d := cmp.Diff(&tcpip.ErrConnectStarted{}, err); d != "" {
t.Fatalf("Unexpected return value from Connect: %v", err) t.Fatalf("Connect(...) mismatch (-want +got):\n%s", d)
} }
// Receive SYN packet. // Receive SYN packet.
@ -391,7 +392,7 @@ func testV4Accept(t *testing.T, c *context.Context) {
defer c.WQ.EventUnregister(&we) defer c.WQ.EventUnregister(&we)
nep, _, err := c.EP.Accept(nil) nep, _, err := c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -525,7 +526,7 @@ func TestV6AcceptOnV6(t *testing.T) {
defer c.WQ.EventUnregister(&we) defer c.WQ.EventUnregister(&we)
var addr tcpip.FullAddress var addr tcpip.FullAddress
_, _, err := c.EP.Accept(&addr) _, _, err := c.EP.Accept(&addr)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -611,7 +612,7 @@ func testV4ListenClose(t *testing.T, c *context.Context) {
c.WQ.EventRegister(&we, waiter.ReadableEvents) c.WQ.EventRegister(&we, waiter.ReadableEvents)
defer c.WQ.EventUnregister(&we) defer c.WQ.EventUnregister(&we)
nep, _, err := c.EP.Accept(nil) nep, _, err := c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:

View File

@ -87,7 +87,7 @@ func (e *endpointTester) CheckReadFull(t *testing.T, count int, notifyRead <-cha
} }
for w.N != 0 { for w.N != 0 {
_, err := e.ep.Read(&w, tcpip.ReadOptions{}) _, err := e.ep.Read(&w, tcpip.ReadOptions{})
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for receive to be notified. // Wait for receive to be notified.
select { select {
case <-notifyRead: case <-notifyRead:
@ -130,8 +130,8 @@ func TestGiveUpConnect(t *testing.T) {
{ {
err := ep.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort}) err := ep.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort})
if _, ok := err.(*tcpip.ErrConnectStarted); !ok { if d := cmp.Diff(&tcpip.ErrConnectStarted{}, err); d != "" {
t.Fatalf("got ep.Connect(...) = %v, want = %s", err, &tcpip.ErrConnectStarted{}) t.Fatalf("ep.Connect(...) mismatch (-want +got):\n%s", d)
} }
} }
@ -145,8 +145,8 @@ func TestGiveUpConnect(t *testing.T) {
// and stats updates. // and stats updates.
{ {
err := ep.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort}) err := ep.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort})
if _, ok := err.(*tcpip.ErrAborted); !ok { if d := cmp.Diff(&tcpip.ErrAborted{}, err); d != "" {
t.Fatalf("got ep.Connect(...) = %v, want = %s", err, &tcpip.ErrAborted{}) t.Fatalf("ep.Connect(...) mismatch (-want +got):\n%s", d)
} }
} }
@ -202,8 +202,8 @@ func TestActiveFailedConnectionAttemptIncrement(t *testing.T) {
{ {
err := c.EP.Connect(tcpip.FullAddress{NIC: 2, Addr: context.TestAddr, Port: context.TestPort}) err := c.EP.Connect(tcpip.FullAddress{NIC: 2, Addr: context.TestAddr, Port: context.TestPort})
if _, ok := err.(*tcpip.ErrNoRoute); !ok { if d := cmp.Diff(&tcpip.ErrNoRoute{}, err); d != "" {
t.Errorf("got c.EP.Connect(...) = %v, want = %s", err, &tcpip.ErrNoRoute{}) t.Errorf("c.EP.Connect(...) mismatch (-want +got):\n%s", d)
} }
} }
@ -393,7 +393,7 @@ func TestTCPResetSentForACKWhenNotUsingSynCookies(t *testing.T) {
defer wq.EventUnregister(&we) defer wq.EventUnregister(&we)
c.EP, _, err = ep.Accept(nil) c.EP, _, err = ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -936,8 +936,8 @@ func TestUserSuppliedMSSOnConnect(t *testing.T) {
connectAddr := tcpip.FullAddress{Addr: ip.connectAddr, Port: context.TestPort} connectAddr := tcpip.FullAddress{Addr: ip.connectAddr, Port: context.TestPort}
{ {
err := c.EP.Connect(connectAddr) err := c.EP.Connect(connectAddr)
if _, ok := err.(*tcpip.ErrConnectStarted); !ok { if d := cmp.Diff(&tcpip.ErrConnectStarted{}, err); d != "" {
t.Fatalf("Connect(%+v): %s", connectAddr, err) t.Fatalf("Connect(%+v) mismatch (-want +got):\n%s", connectAddr, d)
} }
} }
@ -1543,8 +1543,8 @@ func TestConnectBindToDevice(t *testing.T) {
defer c.WQ.EventUnregister(&waitEntry) defer c.WQ.EventUnregister(&waitEntry)
err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort}) err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort})
if _, ok := err.(*tcpip.ErrConnectStarted); !ok { if d := cmp.Diff(&tcpip.ErrConnectStarted{}, err); d != "" {
t.Fatalf("unexpected return value from Connect: %s", err) t.Fatalf("c.EP.Connect(...) mismatch (-want +got):\n%s", d)
} }
// Receive SYN packet. // Receive SYN packet.
@ -1604,8 +1604,8 @@ func TestSynSent(t *testing.T) {
addr := tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort} addr := tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort}
err := c.EP.Connect(addr) err := c.EP.Connect(addr)
if _, ok := err.(*tcpip.ErrConnectStarted); !ok { if d := cmp.Diff(err, &tcpip.ErrConnectStarted{}); d != "" {
t.Fatalf("got Connect(%+v) = %v, want %s", addr, err, &tcpip.ErrConnectStarted{}) t.Fatalf("Connect(...) mismatch (-want +got):\n%s", d)
} }
// Receive SYN packet. // Receive SYN packet.
@ -2473,7 +2473,7 @@ func TestScaledWindowAccept(t *testing.T) {
defer wq.EventUnregister(&we) defer wq.EventUnregister(&we)
c.EP, _, err = ep.Accept(nil) c.EP, _, err = ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -2545,7 +2545,7 @@ func TestNonScaledWindowAccept(t *testing.T) {
defer wq.EventUnregister(&we) defer wq.EventUnregister(&we)
c.EP, _, err = ep.Accept(nil) c.EP, _, err = ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -3077,8 +3077,8 @@ func TestSetTTL(t *testing.T) {
{ {
err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort}) err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort})
if _, ok := err.(*tcpip.ErrConnectStarted); !ok { if d := cmp.Diff(&tcpip.ErrConnectStarted{}, err); d != "" {
t.Fatalf("unexpected return value from Connect: %s", err) t.Fatalf("c.EP.Connect(...) mismatch (-want +got):\n%s", d)
} }
} }
@ -3137,7 +3137,7 @@ func TestPassiveSendMSSLessThanMTU(t *testing.T) {
defer wq.EventUnregister(&we) defer wq.EventUnregister(&we)
c.EP, _, err = ep.Accept(nil) c.EP, _, err = ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -3191,7 +3191,7 @@ func TestSynCookiePassiveSendMSSLessThanMTU(t *testing.T) {
defer wq.EventUnregister(&we) defer wq.EventUnregister(&we)
c.EP, _, err = ep.Accept(nil) c.EP, _, err = ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -3266,8 +3266,8 @@ func TestSynOptionsOnActiveConnect(t *testing.T) {
{ {
err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort}) err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort})
if _, ok := err.(*tcpip.ErrConnectStarted); !ok { if d := cmp.Diff(&tcpip.ErrConnectStarted{}, err); d != "" {
t.Fatalf("got c.EP.Connect(...) = %v, want = %s", err, &tcpip.ErrConnectStarted{}) t.Fatalf("c.EP.Connect(...) mismatch (-want +got):\n%s", d)
} }
} }
@ -3385,8 +3385,8 @@ loop:
case <-ch: case <-ch:
// Expect the state to be StateError and subsequent Reads to fail with HardError. // Expect the state to be StateError and subsequent Reads to fail with HardError.
_, err := c.EP.Read(ioutil.Discard, tcpip.ReadOptions{}) _, err := c.EP.Read(ioutil.Discard, tcpip.ReadOptions{})
if _, ok := err.(*tcpip.ErrConnectionReset); !ok { if d := cmp.Diff(&tcpip.ErrConnectionReset{}, err); d != "" {
t.Fatalf("got c.EP.Read() = %v, want = %s", err, &tcpip.ErrConnectionReset{}) t.Fatalf("c.EP.Read() mismatch (-want +got):\n%s", d)
} }
break loop break loop
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
@ -3436,8 +3436,8 @@ func TestSendOnResetConnection(t *testing.T) {
var r bytes.Reader var r bytes.Reader
r.Reset(make([]byte, 10)) r.Reset(make([]byte, 10))
_, err := c.EP.Write(&r, tcpip.WriteOptions{}) _, err := c.EP.Write(&r, tcpip.WriteOptions{})
if _, ok := err.(*tcpip.ErrConnectionReset); !ok { if d := cmp.Diff(&tcpip.ErrConnectionReset{}, err); d != "" {
t.Fatalf("got c.EP.Write(...) = %v, want = %s", err, &tcpip.ErrConnectionReset{}) t.Fatalf("c.EP.Write(...) mismatch (-want +got):\n%s", d)
} }
} }
@ -4390,8 +4390,8 @@ func TestReadAfterClosedState(t *testing.T) {
var buf bytes.Buffer var buf bytes.Buffer
{ {
_, err := c.EP.Read(&buf, tcpip.ReadOptions{Peek: true}) _, err := c.EP.Read(&buf, tcpip.ReadOptions{Peek: true})
if _, ok := err.(*tcpip.ErrClosedForReceive); !ok { if d := cmp.Diff(&tcpip.ErrClosedForReceive{}, err); d != "" {
t.Fatalf("c.EP.Read(_, {Peek: true}) = %v, %s; want _, %s", res, err, &tcpip.ErrClosedForReceive{}) t.Fatalf("c.EP.Read(_, {Peek: true}) mismatch (-want +got):\n%s", d)
} }
} }
} }
@ -4435,8 +4435,8 @@ func TestReusePort(t *testing.T) {
} }
{ {
err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort}) err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort})
if _, ok := err.(*tcpip.ErrConnectStarted); !ok { if d := cmp.Diff(&tcpip.ErrConnectStarted{}, err); d != "" {
t.Fatalf("got c.EP.Connect(...) = %v, want = %s", err, &tcpip.ErrConnectStarted{}) t.Fatalf("c.EP.Connect(...) mismatch (-want +got):\n%s", d)
} }
} }
c.EP.Close() c.EP.Close()
@ -4724,8 +4724,8 @@ func TestSelfConnect(t *testing.T) {
{ {
err := ep.Connect(tcpip.FullAddress{Addr: context.StackAddr, Port: context.StackPort}) err := ep.Connect(tcpip.FullAddress{Addr: context.StackAddr, Port: context.StackPort})
if _, ok := err.(*tcpip.ErrConnectStarted); !ok { if d := cmp.Diff(&tcpip.ErrConnectStarted{}, err); d != "" {
t.Fatalf("got ep.Connect(...) = %v, want = %s", err, &tcpip.ErrConnectStarted{}) t.Fatalf("ep.Connect(...) mismatch (-want +got):\n%s", d)
} }
} }
@ -5452,7 +5452,7 @@ func TestListenBacklogFull(t *testing.T) {
for i := 0; i < listenBacklog; i++ { for i := 0; i < listenBacklog; i++ {
_, _, err = c.EP.Accept(nil) _, _, err = c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -5469,7 +5469,7 @@ func TestListenBacklogFull(t *testing.T) {
// Now verify that there are no more connections that can be accepted. // Now verify that there are no more connections that can be accepted.
_, _, err = c.EP.Accept(nil) _, _, err = c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); !ok { if !cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
select { select {
case <-ch: case <-ch:
t.Fatalf("unexpected endpoint delivered on Accept: %+v", c.EP) t.Fatalf("unexpected endpoint delivered on Accept: %+v", c.EP)
@ -5481,7 +5481,7 @@ func TestListenBacklogFull(t *testing.T) {
executeHandshake(t, c, context.TestPort+lastPortOffset, false /*synCookieInUse */) executeHandshake(t, c, context.TestPort+lastPortOffset, false /*synCookieInUse */)
newEP, _, err := c.EP.Accept(nil) newEP, _, err := c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -5794,7 +5794,7 @@ func TestListenSynRcvdQueueFull(t *testing.T) {
// Try to accept the connections in the backlog. // Try to accept the connections in the backlog.
newEP, _, err := c.EP.Accept(nil) newEP, _, err := c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -5865,7 +5865,7 @@ func TestListenBacklogFullSynCookieInUse(t *testing.T) {
defer c.WQ.EventUnregister(&we) defer c.WQ.EventUnregister(&we)
_, _, err = c.EP.Accept(nil) _, _, err = c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -5881,7 +5881,7 @@ func TestListenBacklogFullSynCookieInUse(t *testing.T) {
// Now verify that there are no more connections that can be accepted. // Now verify that there are no more connections that can be accepted.
_, _, err = c.EP.Accept(nil) _, _, err = c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); !ok { if !cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
select { select {
case <-ch: case <-ch:
t.Fatalf("unexpected endpoint delivered on Accept: %+v", c.EP) t.Fatalf("unexpected endpoint delivered on Accept: %+v", c.EP)
@ -6020,7 +6020,7 @@ func TestSynRcvdBadSeqNumber(t *testing.T) {
t.Fatalf("Accept failed: %s", err) t.Fatalf("Accept failed: %s", err)
} }
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Try to accept the connections in the backlog. // Try to accept the connections in the backlog.
we, ch := waiter.NewChannelEntry(nil) we, ch := waiter.NewChannelEntry(nil)
c.WQ.EventRegister(&we, waiter.ReadableEvents) c.WQ.EventRegister(&we, waiter.ReadableEvents)
@ -6088,7 +6088,7 @@ func TestPassiveConnectionAttemptIncrement(t *testing.T) {
// Verify that there is only one acceptable connection at this point. // Verify that there is only one acceptable connection at this point.
_, _, err = c.EP.Accept(nil) _, _, err = c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -6158,7 +6158,7 @@ func TestPassiveFailedConnectionAttemptIncrement(t *testing.T) {
// Now check that there is one acceptable connections. // Now check that there is one acceptable connections.
_, _, err = c.EP.Accept(nil) _, _, err = c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -6210,7 +6210,7 @@ func TestEndpointBindListenAcceptState(t *testing.T) {
defer wq.EventUnregister(&we) defer wq.EventUnregister(&we)
aep, _, err := ep.Accept(nil) aep, _, err := ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -6228,8 +6228,8 @@ func TestEndpointBindListenAcceptState(t *testing.T) {
} }
{ {
err := aep.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort}) err := aep.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort})
if _, ok := err.(*tcpip.ErrAlreadyConnected); !ok { if d := cmp.Diff(&tcpip.ErrAlreadyConnected{}, err); d != "" {
t.Errorf("unexpected error attempting to call connect on an established endpoint, got: %v, want: %s", err, &tcpip.ErrAlreadyConnected{}) t.Errorf("Connect(...) mismatch (-want +got):\n%s", d)
} }
} }
// Listening endpoint remains in listen state. // Listening endpoint remains in listen state.
@ -6349,7 +6349,7 @@ func TestReceiveBufferAutoTuningApplicationLimited(t *testing.T) {
// window increases to the full available buffer size. // window increases to the full available buffer size.
for { for {
_, err := c.EP.Read(ioutil.Discard, tcpip.ReadOptions{}) _, err := c.EP.Read(ioutil.Discard, tcpip.ReadOptions{})
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
break break
} }
} }
@ -6480,7 +6480,7 @@ func TestReceiveBufferAutoTuning(t *testing.T) {
totalCopied := 0 totalCopied := 0
for { for {
res, err := c.EP.Read(ioutil.Discard, tcpip.ReadOptions{}) res, err := c.EP.Read(ioutil.Discard, tcpip.ReadOptions{})
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
break break
} }
totalCopied += res.Count totalCopied += res.Count
@ -6672,7 +6672,7 @@ func TestTCPTimeWaitRSTIgnored(t *testing.T) {
defer wq.EventUnregister(&we) defer wq.EventUnregister(&we)
c.EP, _, err = ep.Accept(nil) c.EP, _, err = ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -6791,7 +6791,7 @@ func TestTCPTimeWaitOutOfOrder(t *testing.T) {
defer wq.EventUnregister(&we) defer wq.EventUnregister(&we)
c.EP, _, err = ep.Accept(nil) c.EP, _, err = ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -6898,7 +6898,7 @@ func TestTCPTimeWaitNewSyn(t *testing.T) {
defer wq.EventUnregister(&we) defer wq.EventUnregister(&we)
c.EP, _, err = ep.Accept(nil) c.EP, _, err = ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -6988,7 +6988,7 @@ func TestTCPTimeWaitNewSyn(t *testing.T) {
// Try to accept the connection. // Try to accept the connection.
c.EP, _, err = ep.Accept(nil) c.EP, _, err = ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -7062,7 +7062,7 @@ func TestTCPTimeWaitDuplicateFINExtendsTimeWait(t *testing.T) {
defer wq.EventUnregister(&we) defer wq.EventUnregister(&we)
c.EP, _, err = ep.Accept(nil) c.EP, _, err = ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -7212,7 +7212,7 @@ func TestTCPCloseWithData(t *testing.T) {
defer wq.EventUnregister(&we) defer wq.EventUnregister(&we)
c.EP, _, err = ep.Accept(nil) c.EP, _, err = ep.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); ok { if cmp.Equal(&tcpip.ErrWouldBlock{}, err) {
// Wait for connection to be established. // Wait for connection to be established.
select { select {
case <-ch: case <-ch:
@ -7643,8 +7643,8 @@ func TestTCPDeferAccept(t *testing.T) {
irs, iss := executeHandshake(t, c, context.TestPort, false /* synCookiesInUse */) irs, iss := executeHandshake(t, c, context.TestPort, false /* synCookiesInUse */)
_, _, err := c.EP.Accept(nil) _, _, err := c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); !ok { if d := cmp.Diff(&tcpip.ErrWouldBlock{}, err); d != "" {
t.Fatalf("got c.EP.Accept(nil) = %v, want: %s", err, &tcpip.ErrWouldBlock{}) t.Fatalf("c.EP.Accept(nil) mismatch (-want +got):\n%s", d)
} }
// Send data. This should result in an acceptable endpoint. // Send data. This should result in an acceptable endpoint.
@ -7702,8 +7702,8 @@ func TestTCPDeferAcceptTimeout(t *testing.T) {
irs, iss := executeHandshake(t, c, context.TestPort, false /* synCookiesInUse */) irs, iss := executeHandshake(t, c, context.TestPort, false /* synCookiesInUse */)
_, _, err := c.EP.Accept(nil) _, _, err := c.EP.Accept(nil)
if _, ok := err.(*tcpip.ErrWouldBlock); !ok { if d := cmp.Diff(&tcpip.ErrWouldBlock{}, err); d != "" {
t.Fatalf("got c.EP.Accept(nil) = %v, want: %s", err, &tcpip.ErrWouldBlock{}) t.Fatalf("c.EP.Accept(nil) mismatch (-want +got):\n%s", d)
} }
// Sleep for a little of the tcpDeferAccept timeout. // Sleep for a little of the tcpDeferAccept timeout.