mirror of
https://github.com/golang/net.git
synced 2026-03-31 10:27:08 +09:00
http2: don't rely on double-close of a net.Conn failing
The js_wasm net.Conn implementation doesn't return an error on double-closing a connection. Update tests to not rely on this behavior. Change-Id: I674c6cd6364b7351d627626cf5bd9f59b3c2b96c Reviewed-on: https://go-review.googlesource.com/c/net/+/432515 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
@@ -5930,6 +5930,20 @@ func TestTransportClosesConnAfterGoAwayLastStream(t *testing.T) {
|
||||
testTransportClosesConnAfterGoAway(t, 1)
|
||||
}
|
||||
|
||||
type closeOnceConn struct {
|
||||
net.Conn
|
||||
closed uint32
|
||||
}
|
||||
|
||||
var errClosed = errors.New("Close of closed connection")
|
||||
|
||||
func (c *closeOnceConn) Close() error {
|
||||
if atomic.CompareAndSwapUint32(&c.closed, 0, 1) {
|
||||
return c.Conn.Close()
|
||||
}
|
||||
return errClosed
|
||||
}
|
||||
|
||||
// testTransportClosesConnAfterGoAway verifies that the transport
|
||||
// closes a connection after reading a GOAWAY from it.
|
||||
//
|
||||
@@ -5938,6 +5952,7 @@ func TestTransportClosesConnAfterGoAwayLastStream(t *testing.T) {
|
||||
// when 1, the transport reads the response after receiving the GOAWAY.
|
||||
func testTransportClosesConnAfterGoAway(t *testing.T, lastStream uint32) {
|
||||
ct := newClientTester(t)
|
||||
ct.cc = &closeOnceConn{Conn: ct.cc}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
@@ -5951,12 +5966,10 @@ func testTransportClosesConnAfterGoAway(t *testing.T, lastStream uint32) {
|
||||
if gotErr, wantErr := err != nil, lastStream == 0; gotErr != wantErr {
|
||||
t.Errorf("RoundTrip got error %v (want error: %v)", err, wantErr)
|
||||
}
|
||||
if err = ct.cc.Close(); err == nil {
|
||||
err = fmt.Errorf("expected error on Close")
|
||||
} else if strings.Contains(err.Error(), "use of closed network") {
|
||||
err = nil
|
||||
if err = ct.cc.Close(); err != errClosed {
|
||||
return fmt.Errorf("ct.cc.Close() = %v, want errClosed", err)
|
||||
}
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
ct.server = func() error {
|
||||
|
||||
Reference in New Issue
Block a user