2014-04-19 01:25:11 +04:00
|
|
|
// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
|
2013-10-16 20:41:47 +04:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package websocket
|
|
|
|
|
|
|
|
import (
|
2015-10-09 08:47:23 +03:00
|
|
|
"bufio"
|
2013-10-16 20:41:47 +04:00
|
|
|
"bytes"
|
2016-01-19 20:20:21 +03:00
|
|
|
"errors"
|
2013-10-16 20:41:47 +04:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net"
|
2015-08-11 20:14:32 +03:00
|
|
|
"reflect"
|
2018-08-18 05:50:34 +03:00
|
|
|
"sync"
|
2013-10-16 20:41:47 +04:00
|
|
|
"testing"
|
|
|
|
"testing/iotest"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2014-04-20 18:20:03 +04:00
|
|
|
var _ net.Error = errWriteTimeout
|
2013-12-24 00:01:25 +04:00
|
|
|
|
2013-10-16 20:41:47 +04:00
|
|
|
type fakeNetConn struct {
|
|
|
|
io.Reader
|
|
|
|
io.Writer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c fakeNetConn) Close() error { return nil }
|
2016-11-02 19:41:43 +03:00
|
|
|
func (c fakeNetConn) LocalAddr() net.Addr { return localAddr }
|
|
|
|
func (c fakeNetConn) RemoteAddr() net.Addr { return remoteAddr }
|
2013-10-16 20:41:47 +04:00
|
|
|
func (c fakeNetConn) SetDeadline(t time.Time) error { return nil }
|
|
|
|
func (c fakeNetConn) SetReadDeadline(t time.Time) error { return nil }
|
|
|
|
func (c fakeNetConn) SetWriteDeadline(t time.Time) error { return nil }
|
|
|
|
|
2016-11-02 19:41:43 +03:00
|
|
|
type fakeAddr int
|
|
|
|
|
|
|
|
var (
|
|
|
|
localAddr = fakeAddr(1)
|
|
|
|
remoteAddr = fakeAddr(2)
|
|
|
|
)
|
|
|
|
|
|
|
|
func (a fakeAddr) Network() string {
|
|
|
|
return "net"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a fakeAddr) String() string {
|
|
|
|
return "str"
|
|
|
|
}
|
|
|
|
|
2018-08-18 05:50:34 +03:00
|
|
|
// newTestConn creates a connnection backed by a fake network connection using
|
|
|
|
// default values for buffering.
|
|
|
|
func newTestConn(r io.Reader, w io.Writer, isServer bool) *Conn {
|
|
|
|
return newConn(fakeNetConn{Reader: r, Writer: w}, isServer, 1024, 1024, nil, nil, nil)
|
|
|
|
}
|
|
|
|
|
2013-10-16 20:41:47 +04:00
|
|
|
func TestFraming(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2019-08-25 04:17:28 +03:00
|
|
|
frameSizes := []int{
|
|
|
|
0, 1, 2, 124, 125, 126, 127, 128, 129, 65534, 65535,
|
|
|
|
// 65536, 65537
|
|
|
|
}
|
2013-10-16 20:41:47 +04:00
|
|
|
var readChunkers = []struct {
|
|
|
|
name string
|
|
|
|
f func(io.Reader) io.Reader
|
|
|
|
}{
|
|
|
|
{"half", iotest.HalfReader},
|
|
|
|
{"one", iotest.OneByteReader},
|
|
|
|
{"asis", func(r io.Reader) io.Reader { return r }},
|
|
|
|
}
|
|
|
|
writeBuf := make([]byte, 65537)
|
|
|
|
for i := range writeBuf {
|
|
|
|
writeBuf[i] = byte(i)
|
|
|
|
}
|
2016-11-02 19:41:43 +03:00
|
|
|
var writers = []struct {
|
|
|
|
name string
|
|
|
|
f func(w io.Writer, n int) (int, error)
|
|
|
|
}{
|
|
|
|
{"iocopy", func(w io.Writer, n int) (int, error) {
|
|
|
|
nn, err := io.Copy(w, bytes.NewReader(writeBuf[:n]))
|
|
|
|
return int(nn), err
|
|
|
|
}},
|
|
|
|
{"write", func(w io.Writer, n int) (int, error) {
|
|
|
|
return w.Write(writeBuf[:n])
|
|
|
|
}},
|
|
|
|
{"string", func(w io.Writer, n int) (int, error) {
|
|
|
|
return io.WriteString(w, string(writeBuf[:n]))
|
|
|
|
}},
|
|
|
|
}
|
2013-10-16 20:41:47 +04:00
|
|
|
|
2016-10-18 03:30:22 +03:00
|
|
|
for _, compress := range []bool{false, true} {
|
|
|
|
for _, isServer := range []bool{true, false} {
|
|
|
|
for _, chunker := range readChunkers {
|
2013-10-16 20:41:47 +04:00
|
|
|
|
2016-10-18 03:30:22 +03:00
|
|
|
var connBuf bytes.Buffer
|
2018-08-18 05:50:34 +03:00
|
|
|
wc := newTestConn(nil, &connBuf, isServer)
|
|
|
|
rc := newTestConn(chunker.f(&connBuf), nil, !isServer)
|
2016-10-18 03:30:22 +03:00
|
|
|
if compress {
|
|
|
|
wc.newCompressionWriter = compressNoContextTakeover
|
|
|
|
rc.newDecompressionReader = decompressNoContextTakeover
|
|
|
|
}
|
|
|
|
for _, n := range frameSizes {
|
2016-11-02 19:41:43 +03:00
|
|
|
for _, writer := range writers {
|
|
|
|
name := fmt.Sprintf("z:%v, s:%v, r:%s, n:%d w:%s", compress, isServer, chunker.name, n, writer.name)
|
2013-10-16 20:41:47 +04:00
|
|
|
|
2016-10-18 03:30:22 +03:00
|
|
|
w, err := wc.NextWriter(TextMessage)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s: wc.NextWriter() returned %v", name, err)
|
|
|
|
continue
|
|
|
|
}
|
2016-11-02 19:41:43 +03:00
|
|
|
nn, err := writer.f(w, n)
|
2016-10-18 03:30:22 +03:00
|
|
|
if err != nil || nn != n {
|
|
|
|
t.Errorf("%s: w.Write(writeBuf[:n]) returned %d, %v", name, nn, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
err = w.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s: w.Close() returned %v", name, err)
|
|
|
|
continue
|
|
|
|
}
|
2013-10-16 20:41:47 +04:00
|
|
|
|
2016-10-18 03:30:22 +03:00
|
|
|
opCode, r, err := rc.NextReader()
|
|
|
|
if err != nil || opCode != TextMessage {
|
|
|
|
t.Errorf("%s: NextReader() returned %d, r, %v", name, opCode, err)
|
|
|
|
continue
|
|
|
|
}
|
2019-08-25 04:17:28 +03:00
|
|
|
|
2023-08-26 23:01:45 +03:00
|
|
|
rbuf, err := io.ReadAll(r)
|
2016-10-18 03:30:22 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s: ReadFull() returned rbuf, %v", name, err)
|
|
|
|
continue
|
|
|
|
}
|
2013-10-16 20:41:47 +04:00
|
|
|
|
2016-10-18 03:30:22 +03:00
|
|
|
if len(rbuf) != n {
|
|
|
|
t.Errorf("%s: len(rbuf) is %d, want %d", name, len(rbuf), n)
|
|
|
|
continue
|
|
|
|
}
|
2013-10-16 20:41:47 +04:00
|
|
|
|
2016-10-18 03:30:22 +03:00
|
|
|
for i, b := range rbuf {
|
|
|
|
if byte(i) != b {
|
|
|
|
t.Errorf("%s: bad byte at offset %d", name, i)
|
|
|
|
break
|
|
|
|
}
|
2013-10-16 20:41:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-22 08:47:31 +03:00
|
|
|
func TestConcurrencyWriteControl(t *testing.T) {
|
|
|
|
const message = "this is a ping/pong messsage"
|
|
|
|
loop := 10
|
|
|
|
workers := 10
|
|
|
|
for i := 0; i < loop; i++ {
|
|
|
|
var connBuf bytes.Buffer
|
|
|
|
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wc := newTestConn(nil, &connBuf, true)
|
|
|
|
|
|
|
|
for i := 0; i < workers; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
if err := wc.WriteControl(PongMessage, []byte(message), time.Now().Add(time.Second)); err != nil {
|
|
|
|
t.Errorf("concurrently wc.WriteControl() returned %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
wc.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-06 00:56:34 +04:00
|
|
|
func TestControl(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2014-07-06 00:56:34 +04:00
|
|
|
const message = "this is a ping/pong messsage"
|
|
|
|
for _, isServer := range []bool{true, false} {
|
|
|
|
for _, isWriteControl := range []bool{true, false} {
|
|
|
|
name := fmt.Sprintf("s:%v, wc:%v", isServer, isWriteControl)
|
|
|
|
var connBuf bytes.Buffer
|
2018-08-18 05:50:34 +03:00
|
|
|
wc := newTestConn(nil, &connBuf, isServer)
|
|
|
|
rc := newTestConn(&connBuf, nil, !isServer)
|
2014-07-06 00:56:34 +04:00
|
|
|
if isWriteControl {
|
2023-08-26 23:01:45 +03:00
|
|
|
if err := wc.WriteControl(PongMessage, []byte(message), time.Now().Add(time.Second)); err != nil {
|
|
|
|
t.Errorf("%s: wc.WriteControl() returned %v", name, err)
|
|
|
|
continue
|
|
|
|
}
|
2014-07-06 00:56:34 +04:00
|
|
|
} else {
|
|
|
|
w, err := wc.NextWriter(PongMessage)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%s: wc.NextWriter() returned %v", name, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _, err := w.Write([]byte(message)); err != nil {
|
|
|
|
t.Errorf("%s: w.Write() returned %v", name, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err := w.Close(); err != nil {
|
|
|
|
t.Errorf("%s: w.Close() returned %v", name, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var actualMessage string
|
|
|
|
rc.SetPongHandler(func(s string) error { actualMessage = s; return nil })
|
2023-08-26 23:01:45 +03:00
|
|
|
if _, _, err := rc.NextReader(); err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2014-07-06 00:56:34 +04:00
|
|
|
if actualMessage != message {
|
|
|
|
t.Errorf("%s: pong=%q, want %q", name, actualMessage, message)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-18 05:50:34 +03:00
|
|
|
// simpleBufferPool is an implementation of BufferPool for TestWriteBufferPool.
|
|
|
|
type simpleBufferPool struct {
|
|
|
|
v interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *simpleBufferPool) Get() interface{} {
|
|
|
|
v := p.v
|
|
|
|
p.v = nil
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *simpleBufferPool) Put(v interface{}) {
|
|
|
|
p.v = v
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWriteBufferPool(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2018-09-25 02:26:12 +03:00
|
|
|
const message = "Now is the time for all good people to come to the aid of the party."
|
|
|
|
|
2018-08-18 05:50:34 +03:00
|
|
|
var buf bytes.Buffer
|
|
|
|
var pool simpleBufferPool
|
|
|
|
rc := newTestConn(&buf, nil, false)
|
|
|
|
|
2018-09-25 02:26:12 +03:00
|
|
|
// Specify writeBufferSize smaller than message size to ensure that pooling
|
|
|
|
// works with fragmented messages.
|
|
|
|
wc := newConn(fakeNetConn{Writer: &buf}, true, 1024, len(message)-1, &pool, nil, nil)
|
|
|
|
|
2018-08-18 05:50:34 +03:00
|
|
|
if wc.writeBuf != nil {
|
|
|
|
t.Fatal("writeBuf not nil after create")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Part 1: test NextWriter/Write/Close
|
|
|
|
|
|
|
|
w, err := wc.NextWriter(TextMessage)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("wc.NextWriter() returned %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if wc.writeBuf == nil {
|
|
|
|
t.Fatal("writeBuf is nil after NextWriter")
|
|
|
|
}
|
|
|
|
|
|
|
|
writeBufAddr := &wc.writeBuf[0]
|
|
|
|
|
|
|
|
if _, err := io.WriteString(w, message); err != nil {
|
|
|
|
t.Fatalf("io.WriteString(w, message) returned %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := w.Close(); err != nil {
|
|
|
|
t.Fatalf("w.Close() returned %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if wc.writeBuf != nil {
|
|
|
|
t.Fatal("writeBuf not nil after w.Close()")
|
|
|
|
}
|
|
|
|
|
|
|
|
if wpd, ok := pool.v.(writePoolData); !ok || len(wpd.buf) == 0 || &wpd.buf[0] != writeBufAddr {
|
|
|
|
t.Fatal("writeBuf not returned to pool")
|
|
|
|
}
|
|
|
|
|
|
|
|
opCode, p, err := rc.ReadMessage()
|
|
|
|
if opCode != TextMessage || err != nil {
|
|
|
|
t.Fatalf("ReadMessage() returned %d, p, %v", opCode, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if s := string(p); s != message {
|
|
|
|
t.Fatalf("message is %s, want %s", s, message)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Part 2: Test WriteMessage.
|
|
|
|
|
|
|
|
if err := wc.WriteMessage(TextMessage, []byte(message)); err != nil {
|
|
|
|
t.Fatalf("wc.WriteMessage() returned %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if wc.writeBuf != nil {
|
|
|
|
t.Fatal("writeBuf not nil after wc.WriteMessage()")
|
|
|
|
}
|
|
|
|
|
|
|
|
if wpd, ok := pool.v.(writePoolData); !ok || len(wpd.buf) == 0 || &wpd.buf[0] != writeBufAddr {
|
|
|
|
t.Fatal("writeBuf not returned to pool after WriteMessage")
|
|
|
|
}
|
|
|
|
|
|
|
|
opCode, p, err = rc.ReadMessage()
|
|
|
|
if opCode != TextMessage || err != nil {
|
|
|
|
t.Fatalf("ReadMessage() returned %d, p, %v", opCode, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if s := string(p); s != message {
|
|
|
|
t.Fatalf("message is %s, want %s", s, message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 02:26:12 +03:00
|
|
|
// TestWriteBufferPoolSync ensures that *sync.Pool works as a buffer pool.
|
2018-08-18 05:50:34 +03:00
|
|
|
func TestWriteBufferPoolSync(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2018-08-18 05:50:34 +03:00
|
|
|
var buf bytes.Buffer
|
|
|
|
var pool sync.Pool
|
|
|
|
wc := newConn(fakeNetConn{Writer: &buf}, true, 1024, 1024, &pool, nil, nil)
|
|
|
|
rc := newTestConn(&buf, nil, false)
|
|
|
|
|
|
|
|
const message = "Hello World!"
|
|
|
|
for i := 0; i < 3; i++ {
|
|
|
|
if err := wc.WriteMessage(TextMessage, []byte(message)); err != nil {
|
|
|
|
t.Fatalf("wc.WriteMessage() returned %v", err)
|
|
|
|
}
|
|
|
|
opCode, p, err := rc.ReadMessage()
|
|
|
|
if opCode != TextMessage || err != nil {
|
|
|
|
t.Fatalf("ReadMessage() returned %d, p, %v", opCode, err)
|
|
|
|
}
|
|
|
|
if s := string(p); s != message {
|
|
|
|
t.Fatalf("message is %s, want %s", s, message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 02:26:12 +03:00
|
|
|
// errorWriter is an io.Writer than returns an error on all writes.
|
|
|
|
type errorWriter struct{}
|
|
|
|
|
2019-06-29 21:55:28 +03:00
|
|
|
func (ew errorWriter) Write(p []byte) (int, error) { return 0, errors.New("error") }
|
2018-09-25 02:26:12 +03:00
|
|
|
|
|
|
|
// TestWriteBufferPoolError ensures that buffer is returned to pool after error
|
|
|
|
// on write.
|
|
|
|
func TestWriteBufferPoolError(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2018-09-25 02:26:12 +03:00
|
|
|
|
|
|
|
// Part 1: Test NextWriter/Write/Close
|
|
|
|
|
|
|
|
var pool simpleBufferPool
|
|
|
|
wc := newConn(fakeNetConn{Writer: errorWriter{}}, true, 1024, 1024, &pool, nil, nil)
|
|
|
|
|
|
|
|
w, err := wc.NextWriter(TextMessage)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("wc.NextWriter() returned %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if wc.writeBuf == nil {
|
|
|
|
t.Fatal("writeBuf is nil after NextWriter")
|
|
|
|
}
|
|
|
|
|
|
|
|
writeBufAddr := &wc.writeBuf[0]
|
|
|
|
|
|
|
|
if _, err := io.WriteString(w, "Hello"); err != nil {
|
|
|
|
t.Fatalf("io.WriteString(w, message) returned %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := w.Close(); err == nil {
|
|
|
|
t.Fatalf("w.Close() did not return error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if wpd, ok := pool.v.(writePoolData); !ok || len(wpd.buf) == 0 || &wpd.buf[0] != writeBufAddr {
|
|
|
|
t.Fatal("writeBuf not returned to pool")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Part 2: Test WriteMessage
|
|
|
|
|
|
|
|
wc = newConn(fakeNetConn{Writer: errorWriter{}}, true, 1024, 1024, &pool, nil, nil)
|
|
|
|
|
|
|
|
if err := wc.WriteMessage(TextMessage, []byte("Hello")); err == nil {
|
|
|
|
t.Fatalf("wc.WriteMessage did not return error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if wpd, ok := pool.v.(writePoolData); !ok || len(wpd.buf) == 0 || &wpd.buf[0] != writeBufAddr {
|
|
|
|
t.Fatal("writeBuf not returned to pool")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 19:41:43 +03:00
|
|
|
func TestCloseFrameBeforeFinalMessageFrame(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2014-07-11 06:36:51 +04:00
|
|
|
const bufSize = 512
|
|
|
|
|
2015-08-11 20:14:32 +03:00
|
|
|
expectedErr := &CloseError{Code: CloseNormalClosure, Text: "hello"}
|
|
|
|
|
2014-07-11 06:36:51 +04:00
|
|
|
var b1, b2 bytes.Buffer
|
2018-08-18 05:50:34 +03:00
|
|
|
wc := newConn(&fakeNetConn{Reader: nil, Writer: &b1}, false, 1024, bufSize, nil, nil, nil)
|
|
|
|
rc := newTestConn(&b1, &b2, true)
|
2014-07-11 06:36:51 +04:00
|
|
|
|
|
|
|
w, _ := wc.NextWriter(BinaryMessage)
|
2023-08-26 23:01:45 +03:00
|
|
|
if _, err := w.Write(make([]byte, bufSize+bufSize/2)); err != nil {
|
|
|
|
t.Fatalf("w.Write() returned %v", err)
|
|
|
|
}
|
|
|
|
if err := wc.WriteControl(CloseMessage, FormatCloseMessage(expectedErr.Code, expectedErr.Text), time.Now().Add(10*time.Second)); err != nil {
|
|
|
|
t.Fatalf("wc.WriteControl() returned %v", err)
|
|
|
|
}
|
2014-07-11 06:36:51 +04:00
|
|
|
w.Close()
|
|
|
|
|
|
|
|
op, r, err := rc.NextReader()
|
|
|
|
if op != BinaryMessage || err != nil {
|
|
|
|
t.Fatalf("NextReader() returned %d, %v", op, err)
|
|
|
|
}
|
2023-08-26 23:01:45 +03:00
|
|
|
_, err = io.Copy(io.Discard, r)
|
2015-08-11 20:14:32 +03:00
|
|
|
if !reflect.DeepEqual(err, expectedErr) {
|
|
|
|
t.Fatalf("io.Copy() returned %v, want %v", err, expectedErr)
|
2014-07-11 06:36:51 +04:00
|
|
|
}
|
|
|
|
_, _, err = rc.NextReader()
|
2015-08-11 20:14:32 +03:00
|
|
|
if !reflect.DeepEqual(err, expectedErr) {
|
|
|
|
t.Fatalf("NextReader() returned %v, want %v", err, expectedErr)
|
2014-07-11 06:36:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-25 08:30:05 +03:00
|
|
|
func TestEOFWithinFrame(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2016-04-25 18:42:53 +03:00
|
|
|
const bufSize = 64
|
2016-04-25 08:30:05 +03:00
|
|
|
|
2016-04-25 18:42:53 +03:00
|
|
|
for n := 0; ; n++ {
|
|
|
|
var b bytes.Buffer
|
2018-08-18 05:50:34 +03:00
|
|
|
wc := newTestConn(nil, &b, false)
|
|
|
|
rc := newTestConn(&b, nil, true)
|
2016-04-25 08:30:05 +03:00
|
|
|
|
2016-04-25 18:42:53 +03:00
|
|
|
w, _ := wc.NextWriter(BinaryMessage)
|
2023-08-26 23:01:45 +03:00
|
|
|
if _, err := w.Write(make([]byte, bufSize)); err != nil {
|
|
|
|
t.Fatalf("%d: w.Write() returned %v", n, err)
|
|
|
|
}
|
2016-04-25 18:42:53 +03:00
|
|
|
w.Close()
|
2016-04-25 08:30:05 +03:00
|
|
|
|
2016-04-25 18:42:53 +03:00
|
|
|
if n >= b.Len() {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
b.Truncate(n)
|
2016-04-25 08:30:05 +03:00
|
|
|
|
2016-04-25 18:42:53 +03:00
|
|
|
op, r, err := rc.NextReader()
|
|
|
|
if err == errUnexpectedEOF {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if op != BinaryMessage || err != nil {
|
|
|
|
t.Fatalf("%d: NextReader() returned %d, %v", n, op, err)
|
|
|
|
}
|
2023-08-26 23:01:45 +03:00
|
|
|
_, err = io.Copy(io.Discard, r)
|
2016-04-25 18:42:53 +03:00
|
|
|
if err != errUnexpectedEOF {
|
|
|
|
t.Fatalf("%d: io.Copy() returned %v, want %v", n, err, errUnexpectedEOF)
|
|
|
|
}
|
|
|
|
_, _, err = rc.NextReader()
|
|
|
|
if err != errUnexpectedEOF {
|
|
|
|
t.Fatalf("%d: NextReader() returned %v, want %v", n, err, errUnexpectedEOF)
|
|
|
|
}
|
2016-04-25 08:30:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-11 06:36:51 +04:00
|
|
|
func TestEOFBeforeFinalFrame(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2014-07-11 06:36:51 +04:00
|
|
|
const bufSize = 512
|
|
|
|
|
|
|
|
var b1, b2 bytes.Buffer
|
2018-08-18 05:50:34 +03:00
|
|
|
wc := newConn(&fakeNetConn{Writer: &b1}, false, 1024, bufSize, nil, nil, nil)
|
|
|
|
rc := newTestConn(&b1, &b2, true)
|
2014-07-11 06:36:51 +04:00
|
|
|
|
|
|
|
w, _ := wc.NextWriter(BinaryMessage)
|
2023-08-26 23:01:45 +03:00
|
|
|
if _, err := w.Write(make([]byte, bufSize+bufSize/2)); err != nil {
|
|
|
|
t.Fatalf("w.Write() returned %v", err)
|
|
|
|
}
|
2014-07-11 06:36:51 +04:00
|
|
|
|
|
|
|
op, r, err := rc.NextReader()
|
|
|
|
if op != BinaryMessage || err != nil {
|
|
|
|
t.Fatalf("NextReader() returned %d, %v", op, err)
|
|
|
|
}
|
2023-08-26 23:01:45 +03:00
|
|
|
_, err = io.Copy(io.Discard, r)
|
2014-11-01 00:52:20 +03:00
|
|
|
if err != errUnexpectedEOF {
|
|
|
|
t.Fatalf("io.Copy() returned %v, want %v", err, errUnexpectedEOF)
|
2014-07-11 06:36:51 +04:00
|
|
|
}
|
|
|
|
_, _, err = rc.NextReader()
|
2014-11-01 00:52:20 +03:00
|
|
|
if err != errUnexpectedEOF {
|
|
|
|
t.Fatalf("NextReader() returned %v, want %v", err, errUnexpectedEOF)
|
2014-07-11 06:36:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 19:41:43 +03:00
|
|
|
func TestWriteAfterMessageWriterClose(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2018-08-18 05:50:34 +03:00
|
|
|
wc := newTestConn(nil, &bytes.Buffer{}, false)
|
2016-11-02 19:41:43 +03:00
|
|
|
w, _ := wc.NextWriter(BinaryMessage)
|
2023-08-26 23:01:45 +03:00
|
|
|
if _, err := io.WriteString(w, "hello"); err != nil {
|
|
|
|
t.Fatalf("unexpected error writing, %v", err)
|
|
|
|
}
|
2016-11-02 19:41:43 +03:00
|
|
|
if err := w.Close(); err != nil {
|
|
|
|
t.Fatalf("unxpected error closing message writer, %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := io.WriteString(w, "world"); err == nil {
|
|
|
|
t.Fatalf("no error writing after close")
|
|
|
|
}
|
|
|
|
|
|
|
|
w, _ = wc.NextWriter(BinaryMessage)
|
2023-08-26 23:01:45 +03:00
|
|
|
if _, err := io.WriteString(w, "hello"); err != nil {
|
|
|
|
t.Fatalf("unexpected error writing after getting new writer, %v", err)
|
|
|
|
}
|
2016-11-02 19:41:43 +03:00
|
|
|
|
|
|
|
// close w by getting next writer
|
|
|
|
_, err := wc.NextWriter(BinaryMessage)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting next writer, %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := io.WriteString(w, "world"); err == nil {
|
|
|
|
t.Fatalf("no error writing after close")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-13 03:54:23 +03:00
|
|
|
func TestWriteHandlerDoesNotReturnErrCloseSent(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2023-11-13 03:54:23 +03:00
|
|
|
var b1, b2 bytes.Buffer
|
|
|
|
|
|
|
|
client := newTestConn(&b2, &b1, false)
|
|
|
|
server := newTestConn(&b1, &b2, true)
|
|
|
|
|
|
|
|
msg := FormatCloseMessage(CloseNormalClosure, "")
|
|
|
|
if err := client.WriteMessage(CloseMessage, msg); err != nil {
|
|
|
|
t.Fatalf("unexpected error when writing close message, %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, _, err := server.NextReader(); !IsCloseError(err, 1000) {
|
|
|
|
t.Fatalf("server expects a close message, %v returned", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, _, err := client.NextReader(); !IsCloseError(err, 1000) {
|
|
|
|
t.Fatalf("client expects a close message, %v returned", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-16 20:41:47 +04:00
|
|
|
func TestReadLimit(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2019-08-25 04:17:28 +03:00
|
|
|
t.Run("Test ReadLimit is enforced", func(t *testing.T) {
|
|
|
|
const readLimit = 512
|
|
|
|
message := make([]byte, readLimit+1)
|
2013-10-16 20:41:47 +04:00
|
|
|
|
2019-08-25 04:17:28 +03:00
|
|
|
var b1, b2 bytes.Buffer
|
|
|
|
wc := newConn(&fakeNetConn{Writer: &b1}, false, 1024, readLimit-2, nil, nil, nil)
|
|
|
|
rc := newTestConn(&b1, &b2, true)
|
|
|
|
rc.SetReadLimit(readLimit)
|
2013-10-16 20:41:47 +04:00
|
|
|
|
2019-08-25 04:17:28 +03:00
|
|
|
// Send message at the limit with interleaved pong.
|
|
|
|
w, _ := wc.NextWriter(BinaryMessage)
|
2023-08-26 23:01:45 +03:00
|
|
|
if _, err := w.Write(message[:readLimit-1]); err != nil {
|
|
|
|
t.Fatalf("w.WriteMessage() returned %v", err)
|
|
|
|
}
|
|
|
|
if err := wc.WriteControl(PongMessage, []byte("this is a pong"), time.Now().Add(10*time.Second)); err != nil {
|
|
|
|
t.Fatalf("wc.WriteControl() returned %v", err)
|
|
|
|
}
|
|
|
|
if _, err := w.Write(message[:1]); err != nil {
|
|
|
|
t.Fatalf("w.Write() returned %v", err)
|
|
|
|
}
|
2019-08-25 04:17:28 +03:00
|
|
|
w.Close()
|
2013-10-16 20:41:47 +04:00
|
|
|
|
2019-08-25 04:17:28 +03:00
|
|
|
// Send message larger than the limit.
|
2023-08-26 23:01:45 +03:00
|
|
|
if err := wc.WriteMessage(BinaryMessage, message[:readLimit+1]); err != nil {
|
|
|
|
t.Fatalf("wc.WriteMessage() returned %v", err)
|
|
|
|
}
|
2013-10-16 20:41:47 +04:00
|
|
|
|
2019-08-25 04:17:28 +03:00
|
|
|
op, _, err := rc.NextReader()
|
|
|
|
if op != BinaryMessage || err != nil {
|
|
|
|
t.Fatalf("1: NextReader() returned %d, %v", op, err)
|
|
|
|
}
|
|
|
|
op, r, err := rc.NextReader()
|
|
|
|
if op != BinaryMessage || err != nil {
|
|
|
|
t.Fatalf("2: NextReader() returned %d, %v", op, err)
|
|
|
|
}
|
2023-08-26 23:01:45 +03:00
|
|
|
_, err = io.Copy(io.Discard, r)
|
2019-08-25 04:17:28 +03:00
|
|
|
if err != ErrReadLimit {
|
|
|
|
t.Fatalf("io.Copy() returned %v", err)
|
|
|
|
}
|
|
|
|
})
|
2013-10-16 20:41:47 +04:00
|
|
|
|
2019-08-25 04:17:28 +03:00
|
|
|
t.Run("Test that ReadLimit cannot be overflowed", func(t *testing.T) {
|
|
|
|
const readLimit = 1
|
|
|
|
|
|
|
|
var b1, b2 bytes.Buffer
|
|
|
|
rc := newTestConn(&b1, &b2, true)
|
|
|
|
rc.SetReadLimit(readLimit)
|
|
|
|
|
|
|
|
// First, send a non-final binary message
|
|
|
|
b1.Write([]byte("\x02\x81"))
|
|
|
|
|
|
|
|
// Mask key
|
|
|
|
b1.Write([]byte("\x00\x00\x00\x00"))
|
|
|
|
|
|
|
|
// First payload
|
|
|
|
b1.Write([]byte("A"))
|
|
|
|
|
|
|
|
// Next, send a negative-length, non-final continuation frame
|
|
|
|
b1.Write([]byte("\x00\xFF\x80\x00\x00\x00\x00\x00\x00\x00"))
|
|
|
|
|
|
|
|
// Mask key
|
|
|
|
b1.Write([]byte("\x00\x00\x00\x00"))
|
|
|
|
|
|
|
|
// Next, send a too long, final continuation frame
|
|
|
|
b1.Write([]byte("\x80\xFF\x00\x00\x00\x00\x00\x00\x00\x05"))
|
|
|
|
|
|
|
|
// Mask key
|
|
|
|
b1.Write([]byte("\x00\x00\x00\x00"))
|
|
|
|
|
|
|
|
// Too-long payload
|
|
|
|
b1.Write([]byte("BCDEF"))
|
|
|
|
|
|
|
|
op, r, err := rc.NextReader()
|
|
|
|
if op != BinaryMessage || err != nil {
|
|
|
|
t.Fatalf("1: NextReader() returned %d, %v", op, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var buf [10]byte
|
|
|
|
var read int
|
|
|
|
n, err := r.Read(buf[:])
|
|
|
|
if err != nil && err != ErrReadLimit {
|
|
|
|
t.Fatalf("unexpected error testing read limit: %v", err)
|
|
|
|
}
|
|
|
|
read += n
|
|
|
|
|
|
|
|
n, err = r.Read(buf[:])
|
|
|
|
if err != nil && err != ErrReadLimit {
|
|
|
|
t.Fatalf("unexpected error testing read limit: %v", err)
|
|
|
|
}
|
|
|
|
read += n
|
|
|
|
|
|
|
|
if err == nil && read > readLimit {
|
|
|
|
t.Fatalf("read limit exceeded: limit %d, read %d", readLimit, read)
|
|
|
|
}
|
|
|
|
})
|
2013-10-16 20:41:47 +04:00
|
|
|
}
|
2014-03-18 18:26:10 +04:00
|
|
|
|
2016-11-02 19:41:43 +03:00
|
|
|
func TestAddrs(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2018-08-18 05:50:34 +03:00
|
|
|
c := newTestConn(nil, nil, true)
|
2016-11-02 19:41:43 +03:00
|
|
|
if c.LocalAddr() != localAddr {
|
|
|
|
t.Errorf("LocalAddr = %v, want %v", c.LocalAddr(), localAddr)
|
|
|
|
}
|
|
|
|
if c.RemoteAddr() != remoteAddr {
|
|
|
|
t.Errorf("RemoteAddr = %v, want %v", c.RemoteAddr(), remoteAddr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-17 16:01:17 +03:00
|
|
|
func TestDeprecatedUnderlyingConn(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2014-03-18 18:26:10 +04:00
|
|
|
var b1, b2 bytes.Buffer
|
|
|
|
fc := fakeNetConn{Reader: &b1, Writer: &b2}
|
2018-08-18 05:50:34 +03:00
|
|
|
c := newConn(fc, true, 1024, 1024, nil, nil, nil)
|
2014-03-18 18:26:10 +04:00
|
|
|
ul := c.UnderlyingConn()
|
|
|
|
if ul != fc {
|
|
|
|
t.Fatalf("Underlying conn is not what it should be.")
|
2022-04-17 16:01:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetConn(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2022-04-17 16:01:17 +03:00
|
|
|
var b1, b2 bytes.Buffer
|
|
|
|
fc := fakeNetConn{Reader: &b1, Writer: &b2}
|
|
|
|
c := newConn(fc, true, 1024, 1024, nil, nil, nil)
|
|
|
|
ul := c.NetConn()
|
|
|
|
if ul != fc {
|
|
|
|
t.Fatalf("Underlying conn is not what it should be.")
|
2014-03-18 18:26:10 +04:00
|
|
|
}
|
|
|
|
}
|
2015-10-09 08:47:23 +03:00
|
|
|
|
|
|
|
func TestBufioReadBytes(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2015-10-09 08:47:23 +03:00
|
|
|
// Test calling bufio.ReadBytes for value longer than read buffer size.
|
|
|
|
|
|
|
|
m := make([]byte, 512)
|
|
|
|
m[len(m)-1] = '\n'
|
|
|
|
|
|
|
|
var b1, b2 bytes.Buffer
|
2018-08-18 05:50:34 +03:00
|
|
|
wc := newConn(fakeNetConn{Writer: &b1}, false, len(m)+64, len(m)+64, nil, nil, nil)
|
|
|
|
rc := newConn(fakeNetConn{Reader: &b1, Writer: &b2}, true, len(m)-64, len(m)-64, nil, nil, nil)
|
2015-10-09 08:47:23 +03:00
|
|
|
|
|
|
|
w, _ := wc.NextWriter(BinaryMessage)
|
2023-08-26 23:01:45 +03:00
|
|
|
if _, err := w.Write(m); err != nil {
|
|
|
|
t.Fatalf("w.Write() returned %v", err)
|
|
|
|
}
|
2015-10-09 08:47:23 +03:00
|
|
|
w.Close()
|
|
|
|
|
|
|
|
op, r, err := rc.NextReader()
|
|
|
|
if op != BinaryMessage || err != nil {
|
|
|
|
t.Fatalf("NextReader() returned %d, %v", op, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
br := bufio.NewReader(r)
|
|
|
|
p, err := br.ReadBytes('\n')
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("ReadBytes() returned %v", err)
|
|
|
|
}
|
|
|
|
if len(p) != len(m) {
|
2017-11-02 17:16:55 +03:00
|
|
|
t.Fatalf("read returned %d bytes, want %d bytes", len(p), len(m))
|
2015-10-09 08:47:23 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-19 20:20:21 +03:00
|
|
|
|
|
|
|
var closeErrorTests = []struct {
|
|
|
|
err error
|
|
|
|
codes []int
|
|
|
|
ok bool
|
|
|
|
}{
|
|
|
|
{&CloseError{Code: CloseNormalClosure}, []int{CloseNormalClosure}, true},
|
|
|
|
{&CloseError{Code: CloseNormalClosure}, []int{CloseNoStatusReceived}, false},
|
|
|
|
{&CloseError{Code: CloseNormalClosure}, []int{CloseNoStatusReceived, CloseNormalClosure}, true},
|
|
|
|
{errors.New("hello"), []int{CloseNormalClosure}, false},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloseError(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2016-01-19 20:20:21 +03:00
|
|
|
for _, tt := range closeErrorTests {
|
|
|
|
ok := IsCloseError(tt.err, tt.codes...)
|
|
|
|
if ok != tt.ok {
|
|
|
|
t.Errorf("IsCloseError(%#v, %#v) returned %v, want %v", tt.err, tt.codes, ok, tt.ok)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 00:06:29 +03:00
|
|
|
|
|
|
|
var unexpectedCloseErrorTests = []struct {
|
|
|
|
err error
|
|
|
|
codes []int
|
|
|
|
ok bool
|
|
|
|
}{
|
|
|
|
{&CloseError{Code: CloseNormalClosure}, []int{CloseNormalClosure}, false},
|
|
|
|
{&CloseError{Code: CloseNormalClosure}, []int{CloseNoStatusReceived}, true},
|
|
|
|
{&CloseError{Code: CloseNormalClosure}, []int{CloseNoStatusReceived, CloseNormalClosure}, false},
|
|
|
|
{errors.New("hello"), []int{CloseNormalClosure}, false},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnexpectedCloseErrors(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2016-01-20 00:06:29 +03:00
|
|
|
for _, tt := range unexpectedCloseErrorTests {
|
|
|
|
ok := IsUnexpectedCloseError(tt.err, tt.codes...)
|
|
|
|
if ok != tt.ok {
|
|
|
|
t.Errorf("IsUnexpectedCloseError(%#v, %#v) returned %v, want %v", tt.err, tt.codes, ok, tt.ok)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-17 02:03:54 +03:00
|
|
|
|
|
|
|
type blockingWriter struct {
|
|
|
|
c1, c2 chan struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w blockingWriter) Write(p []byte) (int, error) {
|
|
|
|
// Allow main to continue
|
|
|
|
close(w.c1)
|
|
|
|
// Wait for panic in main
|
|
|
|
<-w.c2
|
|
|
|
return len(p), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConcurrentWritePanic(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2016-02-17 02:03:54 +03:00
|
|
|
w := blockingWriter{make(chan struct{}), make(chan struct{})}
|
2018-08-18 05:50:34 +03:00
|
|
|
c := newTestConn(nil, w, false)
|
2016-02-17 02:03:54 +03:00
|
|
|
go func() {
|
2023-08-26 23:01:45 +03:00
|
|
|
if err := c.WriteMessage(TextMessage, []byte{}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-02-17 02:03:54 +03:00
|
|
|
}()
|
|
|
|
|
|
|
|
// wait for goroutine to block in write.
|
|
|
|
<-w.c1
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
close(w.c2)
|
|
|
|
if v := recover(); v != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2023-08-26 23:01:45 +03:00
|
|
|
if err := c.WriteMessage(TextMessage, []byte{}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-02-17 02:03:54 +03:00
|
|
|
t.Fatal("should not get here")
|
|
|
|
}
|
|
|
|
|
|
|
|
type failingReader struct{}
|
|
|
|
|
|
|
|
func (r failingReader) Read(p []byte) (int, error) {
|
|
|
|
return 0, io.EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFailedConnectionReadPanic(t *testing.T) {
|
2023-11-22 23:18:31 +03:00
|
|
|
t.Parallel()
|
2018-08-18 05:50:34 +03:00
|
|
|
c := newTestConn(failingReader{}, nil, false)
|
2016-02-17 02:03:54 +03:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if v := recover(); v != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
for i := 0; i < 20000; i++ {
|
2023-08-26 23:01:45 +03:00
|
|
|
_, _, _ = c.ReadMessage()
|
2016-02-17 02:03:54 +03:00
|
|
|
}
|
|
|
|
t.Fatal("should not get here")
|
|
|
|
}
|
2024-01-23 09:50:52 +03:00
|
|
|
|
|
|
|
func TestFormatMessageType(t *testing.T) {
|
|
|
|
str := FormatMessageType(TextMessage)
|
|
|
|
if str != messageTypes[TextMessage] {
|
|
|
|
t.Error("failed to format message type")
|
|
|
|
}
|
|
|
|
|
|
|
|
str = FormatMessageType(CloseMessage)
|
|
|
|
if str != messageTypes[CloseMessage] {
|
|
|
|
t.Error("failed to format message type")
|
|
|
|
}
|
|
|
|
|
|
|
|
str = FormatMessageType(123)
|
|
|
|
if str != messageTypes[123] {
|
|
|
|
t.Error("failed to format message type")
|
|
|
|
}
|
|
|
|
}
|
2024-02-15 05:59:16 +03:00
|
|
|
|
|
|
|
type fakeNetClosedReader struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r fakeNetClosedReader) Read([]byte) (int, error) {
|
|
|
|
return 0, net.ErrClosed
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConnectionClosed(t *testing.T) {
|
|
|
|
var b1, b2 bytes.Buffer
|
|
|
|
|
|
|
|
client := newTestConn(fakeNetClosedReader{}, &b1, false)
|
|
|
|
server := newTestConn(fakeNetClosedReader{}, &b2, true)
|
|
|
|
|
|
|
|
if _, _, err := server.NextReader(); !errors.Is(err, net.ErrClosed) {
|
|
|
|
t.Fatalf("server expects a net.ErrClosed error, %v returned", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, _, err := client.NextReader(); !errors.Is(err, net.ErrClosed) {
|
|
|
|
t.Fatalf("client expects a net.ErrClosed error, %v returned", err)
|
|
|
|
}
|
|
|
|
}
|