Deflake TestCloseRead.

The test needs to wait for CreateEndpoint to return before
cleaning up the stack, otherwise if the netstack is slow to
process the final ACK to the handshake the active side of the
connection can race ahead to the end and start tearing down the
stack.

This results in CreateEndpoint failing with a connection
aborted error.

PiperOrigin-RevId: 446515200
This commit is contained in:
Bhasker Hariharan
2022-05-04 11:55:10 -07:00
committed by gVisor bot
parent da0c67b92a
commit e89e736f16
+8
View File
@@ -265,12 +265,14 @@ func TestCloseRead(t *testing.T) {
t.Fatalf("AddProtocolAddress(%d, %+v, {}): %s", NICID, protocolAddr, err)
}
done := make(chan struct{})
fwd := tcp.NewForwarder(s, 30000, 10, func(r *tcp.ForwarderRequest) {
var wq waiter.Queue
_, err := r.CreateEndpoint(&wq)
if err != nil {
t.Fatalf("r.CreateEndpoint() = %v", err)
}
close(done)
// Endpoint will be closed in deferred s.Close (above).
})
@@ -294,6 +296,12 @@ func TestCloseRead(t *testing.T) {
if n, err := c.Write([]byte("abc123")); n != 6 || err != nil {
t.Errorf("c.Write() = (%d, %v), want (6, nil)", n, err)
}
select {
case <-done:
case <-time.After(1 * time.Second):
t.Fatalf("timed out waiting for r.CreateEndpoint(...) to complete")
}
}
func TestCloseWrite(t *testing.T) {