mirror of https://github.com/gorilla/websocket.git
make tests parallel
This commit is contained in:
parent
871f6bbc74
commit
4a5e66f763
|
@ -142,6 +142,7 @@ func sendRecv(t *testing.T, ws *Conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProxyDial(t *testing.T) {
|
func TestProxyDial(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
@ -180,6 +181,7 @@ func TestProxyDial(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProxyAuthorizationDial(t *testing.T) {
|
func TestProxyAuthorizationDial(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -220,6 +222,7 @@ func TestProxyAuthorizationDial(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDial(t *testing.T) {
|
func TestDial(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -232,6 +235,7 @@ func TestDial(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDialCookieJar(t *testing.T) {
|
func TestDialCookieJar(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -294,6 +298,7 @@ func rootCAs(t *testing.T, s *httptest.Server) *x509.CertPool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDialTLS(t *testing.T) {
|
func TestDialTLS(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newTLSServer(t)
|
s := newTLSServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -308,6 +313,7 @@ func TestDialTLS(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDialTimeout(t *testing.T) {
|
func TestDialTimeout(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -364,6 +370,7 @@ func (c *requireDeadlineNetConn) LocalAddr() net.Addr { return c.c.LocalAddr()
|
||||||
func (c *requireDeadlineNetConn) RemoteAddr() net.Addr { return c.c.RemoteAddr() }
|
func (c *requireDeadlineNetConn) RemoteAddr() net.Addr { return c.c.RemoteAddr() }
|
||||||
|
|
||||||
func TestHandshakeTimeout(t *testing.T) {
|
func TestHandshakeTimeout(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -380,6 +387,7 @@ func TestHandshakeTimeout(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHandshakeTimeoutInContext(t *testing.T) {
|
func TestHandshakeTimeoutInContext(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -401,6 +409,7 @@ func TestHandshakeTimeoutInContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDialBadScheme(t *testing.T) {
|
func TestDialBadScheme(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -412,6 +421,7 @@ func TestDialBadScheme(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDialBadOrigin(t *testing.T) {
|
func TestDialBadOrigin(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -429,6 +439,7 @@ func TestDialBadOrigin(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDialBadHeader(t *testing.T) {
|
func TestDialBadHeader(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -448,6 +459,7 @@ func TestDialBadHeader(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBadMethod(t *testing.T) {
|
func TestBadMethod(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
ws, err := cstUpgrader.Upgrade(w, r, nil)
|
ws, err := cstUpgrader.Upgrade(w, r, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -476,6 +488,7 @@ func TestBadMethod(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDialExtraTokensInRespHeaders(t *testing.T) {
|
func TestDialExtraTokensInRespHeaders(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
challengeKey := r.Header.Get("Sec-Websocket-Key")
|
challengeKey := r.Header.Get("Sec-Websocket-Key")
|
||||||
w.Header().Set("Upgrade", "foo, websocket")
|
w.Header().Set("Upgrade", "foo, websocket")
|
||||||
|
@ -493,6 +506,7 @@ func TestDialExtraTokensInRespHeaders(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHandshake(t *testing.T) {
|
func TestHandshake(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -519,6 +533,7 @@ func TestHandshake(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRespOnBadHandshake(t *testing.T) {
|
func TestRespOnBadHandshake(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
const expectedStatus = http.StatusGone
|
const expectedStatus = http.StatusGone
|
||||||
const expectedBody = "This is the response body."
|
const expectedBody = "This is the response body."
|
||||||
|
|
||||||
|
@ -564,6 +579,7 @@ func (w testLogWriter) Write(p []byte) (int, error) {
|
||||||
|
|
||||||
// TestHost tests handling of host names and confirms that it matches net/http.
|
// TestHost tests handling of host names and confirms that it matches net/http.
|
||||||
func TestHost(t *testing.T) {
|
func TestHost(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
upgrader := Upgrader{}
|
upgrader := Upgrader{}
|
||||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -745,6 +761,7 @@ func TestHost(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDialCompression(t *testing.T) {
|
func TestDialCompression(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -759,6 +776,7 @@ func TestDialCompression(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSocksProxyDial(t *testing.T) {
|
func TestSocksProxyDial(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
s := newServer(t)
|
s := newServer(t)
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -846,6 +864,7 @@ func TestSocksProxyDial(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTracingDialWithContext(t *testing.T) {
|
func TestTracingDialWithContext(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
var headersWrote, requestWrote, getConn, gotConn, connectDone, gotFirstResponseByte bool
|
var headersWrote, requestWrote, getConn, gotConn, connectDone, gotFirstResponseByte bool
|
||||||
trace := &httptrace.ClientTrace{
|
trace := &httptrace.ClientTrace{
|
||||||
|
@ -905,6 +924,7 @@ func TestTracingDialWithContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyTracingDialWithContext(t *testing.T) {
|
func TestEmptyTracingDialWithContext(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
trace := &httptrace.ClientTrace{}
|
trace := &httptrace.ClientTrace{}
|
||||||
ctx := httptrace.WithClientTrace(context.Background(), trace)
|
ctx := httptrace.WithClientTrace(context.Background(), trace)
|
||||||
|
@ -926,6 +946,7 @@ func TestEmptyTracingDialWithContext(t *testing.T) {
|
||||||
|
|
||||||
// TestNetDialConnect tests selection of dial method between NetDial, NetDialContext, NetDialTLS or NetDialTLSContext
|
// TestNetDialConnect tests selection of dial method between NetDial, NetDialContext, NetDialTLS or NetDialTLSContext
|
||||||
func TestNetDialConnect(t *testing.T) {
|
func TestNetDialConnect(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
upgrader := Upgrader{}
|
upgrader := Upgrader{}
|
||||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -1101,6 +1122,7 @@ func TestNetDialConnect(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func TestNextProtos(t *testing.T) {
|
func TestNextProtos(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
ts := httptest.NewUnstartedServer(
|
ts := httptest.NewUnstartedServer(
|
||||||
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}),
|
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}),
|
||||||
)
|
)
|
||||||
|
|
|
@ -20,6 +20,7 @@ var hostPortNoPortTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHostPortNoPort(t *testing.T) {
|
func TestHostPortNoPort(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
for _, tt := range hostPortNoPortTests {
|
for _, tt := range hostPortNoPortTests {
|
||||||
hostPort, hostNoPort := hostPortNoPort(tt.u)
|
hostPort, hostNoPort := hostPortNoPort(tt.u)
|
||||||
if hostPort != tt.hostPort {
|
if hostPort != tt.hostPort {
|
||||||
|
|
|
@ -12,6 +12,7 @@ type nopCloser struct{ io.Writer }
|
||||||
func (nopCloser) Close() error { return nil }
|
func (nopCloser) Close() error { return nil }
|
||||||
|
|
||||||
func TestTruncWriter(t *testing.T) {
|
func TestTruncWriter(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
const data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijlkmnopqrstuvwxyz987654321"
|
const data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijlkmnopqrstuvwxyz987654321"
|
||||||
for n := 1; n <= 10; n++ {
|
for n := 1; n <= 10; n++ {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
|
@ -71,6 +72,7 @@ func BenchmarkWriteWithCompression(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidCompressionLevel(t *testing.T) {
|
func TestValidCompressionLevel(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
c := newTestConn(nil, nil, false)
|
c := newTestConn(nil, nil, false)
|
||||||
for _, level := range []int{minCompressionLevel - 1, maxCompressionLevel + 1} {
|
for _, level := range []int{minCompressionLevel - 1, maxCompressionLevel + 1} {
|
||||||
if err := c.SetCompressionLevel(level); err == nil {
|
if err := c.SetCompressionLevel(level); err == nil {
|
||||||
|
|
19
conn_test.go
19
conn_test.go
|
@ -54,6 +54,7 @@ func newTestConn(r io.Reader, w io.Writer, isServer bool) *Conn {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFraming(t *testing.T) {
|
func TestFraming(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
frameSizes := []int{
|
frameSizes := []int{
|
||||||
0, 1, 2, 124, 125, 126, 127, 128, 129, 65534, 65535,
|
0, 1, 2, 124, 125, 126, 127, 128, 129, 65534, 65535,
|
||||||
// 65536, 65537
|
// 65536, 65537
|
||||||
|
@ -148,6 +149,7 @@ func TestFraming(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestControl(t *testing.T) {
|
func TestControl(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
const message = "this is a ping/pong messsage"
|
const message = "this is a ping/pong messsage"
|
||||||
for _, isServer := range []bool{true, false} {
|
for _, isServer := range []bool{true, false} {
|
||||||
for _, isWriteControl := range []bool{true, false} {
|
for _, isWriteControl := range []bool{true, false} {
|
||||||
|
@ -204,6 +206,7 @@ func (p *simpleBufferPool) Put(v interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWriteBufferPool(t *testing.T) {
|
func TestWriteBufferPool(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
const message = "Now is the time for all good people to come to the aid of the party."
|
const message = "Now is the time for all good people to come to the aid of the party."
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
@ -282,6 +285,7 @@ func TestWriteBufferPool(t *testing.T) {
|
||||||
|
|
||||||
// TestWriteBufferPoolSync ensures that *sync.Pool works as a buffer pool.
|
// TestWriteBufferPoolSync ensures that *sync.Pool works as a buffer pool.
|
||||||
func TestWriteBufferPoolSync(t *testing.T) {
|
func TestWriteBufferPoolSync(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
var pool sync.Pool
|
var pool sync.Pool
|
||||||
wc := newConn(fakeNetConn{Writer: &buf}, true, 1024, 1024, &pool, nil, nil)
|
wc := newConn(fakeNetConn{Writer: &buf}, true, 1024, 1024, &pool, nil, nil)
|
||||||
|
@ -310,6 +314,7 @@ func (ew errorWriter) Write(p []byte) (int, error) { return 0, errors.New("error
|
||||||
// TestWriteBufferPoolError ensures that buffer is returned to pool after error
|
// TestWriteBufferPoolError ensures that buffer is returned to pool after error
|
||||||
// on write.
|
// on write.
|
||||||
func TestWriteBufferPoolError(t *testing.T) {
|
func TestWriteBufferPoolError(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
// Part 1: Test NextWriter/Write/Close
|
// Part 1: Test NextWriter/Write/Close
|
||||||
|
|
||||||
|
@ -353,6 +358,7 @@ func TestWriteBufferPoolError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCloseFrameBeforeFinalMessageFrame(t *testing.T) {
|
func TestCloseFrameBeforeFinalMessageFrame(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
const bufSize = 512
|
const bufSize = 512
|
||||||
|
|
||||||
expectedErr := &CloseError{Code: CloseNormalClosure, Text: "hello"}
|
expectedErr := &CloseError{Code: CloseNormalClosure, Text: "hello"}
|
||||||
|
@ -385,6 +391,7 @@ func TestCloseFrameBeforeFinalMessageFrame(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEOFWithinFrame(t *testing.T) {
|
func TestEOFWithinFrame(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
const bufSize = 64
|
const bufSize = 64
|
||||||
|
|
||||||
for n := 0; ; n++ {
|
for n := 0; ; n++ {
|
||||||
|
@ -422,6 +429,7 @@ func TestEOFWithinFrame(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEOFBeforeFinalFrame(t *testing.T) {
|
func TestEOFBeforeFinalFrame(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
const bufSize = 512
|
const bufSize = 512
|
||||||
|
|
||||||
var b1, b2 bytes.Buffer
|
var b1, b2 bytes.Buffer
|
||||||
|
@ -448,6 +456,7 @@ func TestEOFBeforeFinalFrame(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWriteAfterMessageWriterClose(t *testing.T) {
|
func TestWriteAfterMessageWriterClose(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
wc := newTestConn(nil, &bytes.Buffer{}, false)
|
wc := newTestConn(nil, &bytes.Buffer{}, false)
|
||||||
w, _ := wc.NextWriter(BinaryMessage)
|
w, _ := wc.NextWriter(BinaryMessage)
|
||||||
if _, err := io.WriteString(w, "hello"); err != nil {
|
if _, err := io.WriteString(w, "hello"); err != nil {
|
||||||
|
@ -478,6 +487,7 @@ func TestWriteAfterMessageWriterClose(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWriteHandlerDoesNotReturnErrCloseSent(t *testing.T) {
|
func TestWriteHandlerDoesNotReturnErrCloseSent(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
var b1, b2 bytes.Buffer
|
var b1, b2 bytes.Buffer
|
||||||
|
|
||||||
client := newTestConn(&b2, &b1, false)
|
client := newTestConn(&b2, &b1, false)
|
||||||
|
@ -498,6 +508,7 @@ func TestWriteHandlerDoesNotReturnErrCloseSent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadLimit(t *testing.T) {
|
func TestReadLimit(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
t.Run("Test ReadLimit is enforced", func(t *testing.T) {
|
t.Run("Test ReadLimit is enforced", func(t *testing.T) {
|
||||||
const readLimit = 512
|
const readLimit = 512
|
||||||
message := make([]byte, readLimit+1)
|
message := make([]byte, readLimit+1)
|
||||||
|
@ -596,6 +607,7 @@ func TestReadLimit(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddrs(t *testing.T) {
|
func TestAddrs(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
c := newTestConn(nil, nil, true)
|
c := newTestConn(nil, nil, true)
|
||||||
if c.LocalAddr() != localAddr {
|
if c.LocalAddr() != localAddr {
|
||||||
t.Errorf("LocalAddr = %v, want %v", c.LocalAddr(), localAddr)
|
t.Errorf("LocalAddr = %v, want %v", c.LocalAddr(), localAddr)
|
||||||
|
@ -606,6 +618,7 @@ func TestAddrs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeprecatedUnderlyingConn(t *testing.T) {
|
func TestDeprecatedUnderlyingConn(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
var b1, b2 bytes.Buffer
|
var b1, b2 bytes.Buffer
|
||||||
fc := fakeNetConn{Reader: &b1, Writer: &b2}
|
fc := fakeNetConn{Reader: &b1, Writer: &b2}
|
||||||
c := newConn(fc, true, 1024, 1024, nil, nil, nil)
|
c := newConn(fc, true, 1024, 1024, nil, nil, nil)
|
||||||
|
@ -616,6 +629,7 @@ func TestDeprecatedUnderlyingConn(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNetConn(t *testing.T) {
|
func TestNetConn(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
var b1, b2 bytes.Buffer
|
var b1, b2 bytes.Buffer
|
||||||
fc := fakeNetConn{Reader: &b1, Writer: &b2}
|
fc := fakeNetConn{Reader: &b1, Writer: &b2}
|
||||||
c := newConn(fc, true, 1024, 1024, nil, nil, nil)
|
c := newConn(fc, true, 1024, 1024, nil, nil, nil)
|
||||||
|
@ -626,6 +640,7 @@ func TestNetConn(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBufioReadBytes(t *testing.T) {
|
func TestBufioReadBytes(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
// Test calling bufio.ReadBytes for value longer than read buffer size.
|
// Test calling bufio.ReadBytes for value longer than read buffer size.
|
||||||
|
|
||||||
m := make([]byte, 512)
|
m := make([]byte, 512)
|
||||||
|
@ -668,6 +683,7 @@ var closeErrorTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCloseError(t *testing.T) {
|
func TestCloseError(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
for _, tt := range closeErrorTests {
|
for _, tt := range closeErrorTests {
|
||||||
ok := IsCloseError(tt.err, tt.codes...)
|
ok := IsCloseError(tt.err, tt.codes...)
|
||||||
if ok != tt.ok {
|
if ok != tt.ok {
|
||||||
|
@ -688,6 +704,7 @@ var unexpectedCloseErrorTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnexpectedCloseErrors(t *testing.T) {
|
func TestUnexpectedCloseErrors(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
for _, tt := range unexpectedCloseErrorTests {
|
for _, tt := range unexpectedCloseErrorTests {
|
||||||
ok := IsUnexpectedCloseError(tt.err, tt.codes...)
|
ok := IsUnexpectedCloseError(tt.err, tt.codes...)
|
||||||
if ok != tt.ok {
|
if ok != tt.ok {
|
||||||
|
@ -709,6 +726,7 @@ func (w blockingWriter) Write(p []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConcurrentWritePanic(t *testing.T) {
|
func TestConcurrentWritePanic(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
w := blockingWriter{make(chan struct{}), make(chan struct{})}
|
w := blockingWriter{make(chan struct{}), make(chan struct{})}
|
||||||
c := newTestConn(nil, w, false)
|
c := newTestConn(nil, w, false)
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -740,6 +758,7 @@ func (r failingReader) Read(p []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFailedConnectionReadPanic(t *testing.T) {
|
func TestFailedConnectionReadPanic(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
c := newTestConn(failingReader{}, nil, false)
|
c := newTestConn(failingReader{}, nil, false)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
|
@ -42,4 +42,4 @@ func processMessage(mt int, p []byte) {}
|
||||||
|
|
||||||
// TestX prevents godoc from showing this entire file in the example. Remove
|
// TestX prevents godoc from showing this entire file in the example. Remove
|
||||||
// this function when a second example is added.
|
// this function when a second example is added.
|
||||||
func TestX(t *testing.T) {}
|
func TestX(t *testing.T) { t.Parallel() }
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestJoinMessages(t *testing.T) {
|
func TestJoinMessages(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
messages := []string{"a", "bc", "def", "ghij", "klmno", "0", "12", "345", "6789"}
|
messages := []string{"a", "bc", "def", "ghij", "klmno", "0", "12", "345", "6789"}
|
||||||
for _, readChunk := range []int{1, 2, 3, 4, 5, 6, 7} {
|
for _, readChunk := range []int{1, 2, 3, 4, 5, 6, 7} {
|
||||||
for _, term := range []string{"", ","} {
|
for _, term := range []string{"", ","} {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestJSON(t *testing.T) {
|
func TestJSON(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
wc := newTestConn(nil, &buf, true)
|
wc := newTestConn(nil, &buf, true)
|
||||||
rc := newTestConn(&buf, nil, false)
|
rc := newTestConn(&buf, nil, false)
|
||||||
|
@ -38,6 +39,7 @@ func TestJSON(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPartialJSONRead(t *testing.T) {
|
func TestPartialJSONRead(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
var buf0, buf1 bytes.Buffer
|
var buf0, buf1 bytes.Buffer
|
||||||
wc := newTestConn(nil, &buf0, true)
|
wc := newTestConn(nil, &buf0, true)
|
||||||
rc := newTestConn(&buf0, &buf1, false)
|
rc := newTestConn(&buf0, &buf1, false)
|
||||||
|
@ -91,6 +93,7 @@ func TestPartialJSONRead(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeprecatedJSON(t *testing.T) {
|
func TestDeprecatedJSON(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
wc := newTestConn(nil, &buf, true)
|
wc := newTestConn(nil, &buf, true)
|
||||||
rc := newTestConn(&buf, nil, false)
|
rc := newTestConn(&buf, nil, false)
|
||||||
|
|
|
@ -29,6 +29,7 @@ func notzero(b []byte) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMaskBytes(t *testing.T) {
|
func TestMaskBytes(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
key := [4]byte{1, 2, 3, 4}
|
key := [4]byte{1, 2, 3, 4}
|
||||||
for size := 1; size <= 1024; size++ {
|
for size := 1; size <= 1024; size++ {
|
||||||
for align := 0; align < wordSize; align++ {
|
for align := 0; align < wordSize; align++ {
|
||||||
|
|
|
@ -27,6 +27,7 @@ var subprotocolTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSubprotocols(t *testing.T) {
|
func TestSubprotocols(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
for _, st := range subprotocolTests {
|
for _, st := range subprotocolTests {
|
||||||
r := http.Request{Header: http.Header{"Sec-Websocket-Protocol": {st.h}}}
|
r := http.Request{Header: http.Header{"Sec-Websocket-Protocol": {st.h}}}
|
||||||
protocols := Subprotocols(&r)
|
protocols := Subprotocols(&r)
|
||||||
|
@ -46,6 +47,7 @@ var isWebSocketUpgradeTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsWebSocketUpgrade(t *testing.T) {
|
func TestIsWebSocketUpgrade(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
for _, tt := range isWebSocketUpgradeTests {
|
for _, tt := range isWebSocketUpgradeTests {
|
||||||
ok := IsWebSocketUpgrade(&http.Request{Header: tt.h})
|
ok := IsWebSocketUpgrade(&http.Request{Header: tt.h})
|
||||||
if tt.ok != ok {
|
if tt.ok != ok {
|
||||||
|
@ -55,6 +57,7 @@ func TestIsWebSocketUpgrade(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSubProtocolSelection(t *testing.T) {
|
func TestSubProtocolSelection(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
upgrader := Upgrader{
|
upgrader := Upgrader{
|
||||||
Subprotocols: []string{"foo", "bar", "baz"},
|
Subprotocols: []string{"foo", "bar", "baz"},
|
||||||
}
|
}
|
||||||
|
@ -94,6 +97,7 @@ var checkSameOriginTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckSameOrigin(t *testing.T) {
|
func TestCheckSameOrigin(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
for _, tt := range checkSameOriginTests {
|
for _, tt := range checkSameOriginTests {
|
||||||
ok := checkSameOrigin(tt.r)
|
ok := checkSameOrigin(tt.r)
|
||||||
if tt.ok != ok {
|
if tt.ok != ok {
|
||||||
|
@ -120,6 +124,7 @@ var bufioReuseTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBufioReuse(t *testing.T) {
|
func TestBufioReuse(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
for i, tt := range bufioReuseTests {
|
for i, tt := range bufioReuseTests {
|
||||||
br := bufio.NewReaderSize(strings.NewReader(""), tt.n)
|
br := bufio.NewReaderSize(strings.NewReader(""), tt.n)
|
||||||
bw := bufio.NewWriterSize(&bytes.Buffer{}, tt.n)
|
bw := bufio.NewWriterSize(&bytes.Buffer{}, tt.n)
|
||||||
|
|
|
@ -21,6 +21,7 @@ var equalASCIIFoldTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEqualASCIIFold(t *testing.T) {
|
func TestEqualASCIIFold(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
for _, tt := range equalASCIIFoldTests {
|
for _, tt := range equalASCIIFoldTests {
|
||||||
eq := equalASCIIFold(tt.s, tt.t)
|
eq := equalASCIIFold(tt.s, tt.t)
|
||||||
if eq != tt.eq {
|
if eq != tt.eq {
|
||||||
|
@ -44,6 +45,7 @@ var tokenListContainsValueTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTokenListContainsValue(t *testing.T) {
|
func TestTokenListContainsValue(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
for _, tt := range tokenListContainsValueTests {
|
for _, tt := range tokenListContainsValueTests {
|
||||||
h := http.Header{"Upgrade": {tt.value}}
|
h := http.Header{"Upgrade": {tt.value}}
|
||||||
ok := tokenListContainsValue(h, "Upgrade", "websocket")
|
ok := tokenListContainsValue(h, "Upgrade", "websocket")
|
||||||
|
@ -64,6 +66,7 @@ var isValidChallengeKeyTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsValidChallengeKey(t *testing.T) {
|
func TestIsValidChallengeKey(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
for _, tt := range isValidChallengeKeyTests {
|
for _, tt := range isValidChallengeKeyTests {
|
||||||
ok := isValidChallengeKey(tt.key)
|
ok := isValidChallengeKey(tt.key)
|
||||||
if ok != tt.ok {
|
if ok != tt.ok {
|
||||||
|
@ -105,6 +108,7 @@ var parseExtensionTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseExtensions(t *testing.T) {
|
func TestParseExtensions(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
for _, tt := range parseExtensionTests {
|
for _, tt := range parseExtensionTests {
|
||||||
h := http.Header{http.CanonicalHeaderKey("Sec-WebSocket-Extensions"): {tt.value}}
|
h := http.Header{http.CanonicalHeaderKey("Sec-WebSocket-Extensions"): {tt.value}}
|
||||||
extensions := parseExtensions(h)
|
extensions := parseExtensions(h)
|
||||||
|
|
Loading…
Reference in New Issue