Skip to content

Commit

Permalink
make tests parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
ninedraft committed Nov 22, 2023
1 parent 6f5d213 commit aa1bc5b
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 1 deletion.
22 changes: 22 additions & 0 deletions client_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func sendRecv(t *testing.T, ws *Conn) {
}

func TestProxyDial(t *testing.T) {
t.Parallel()

s := newServer(t)
defer s.Close()

Check failure on line 148 in client_server_test.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

s.Close undefined (type *cstServer has no field or method Close) (typecheck)
Expand Down Expand Up @@ -180,6 +181,7 @@ func TestProxyDial(t *testing.T) {
}

func TestProxyAuthorizationDial(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Check failure on line 186 in client_server_test.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

s.Close undefined (type *cstServer has no field or method Close) (typecheck)

Expand Down Expand Up @@ -220,6 +222,7 @@ func TestProxyAuthorizationDial(t *testing.T) {
}

func TestDial(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Check failure on line 227 in client_server_test.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

s.Close undefined (type *cstServer has no field or method Close) (typecheck)

Expand All @@ -232,6 +235,7 @@ func TestDial(t *testing.T) {
}

func TestDialCookieJar(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Expand Down Expand Up @@ -294,6 +298,7 @@ func rootCAs(t *testing.T, s *httptest.Server) *x509.CertPool {
}

func TestDialTLS(t *testing.T) {
t.Parallel()
s := newTLSServer(t)
defer s.Close()

Expand All @@ -308,6 +313,7 @@ func TestDialTLS(t *testing.T) {
}

func TestDialTimeout(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Expand Down Expand Up @@ -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 TestHandshakeTimeout(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Expand All @@ -380,6 +387,7 @@ func TestHandshakeTimeout(t *testing.T) {
}

func TestHandshakeTimeoutInContext(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Expand All @@ -401,6 +409,7 @@ func TestHandshakeTimeoutInContext(t *testing.T) {
}

func TestDialBadScheme(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Expand All @@ -412,6 +421,7 @@ func TestDialBadScheme(t *testing.T) {
}

func TestDialBadOrigin(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Expand All @@ -429,6 +439,7 @@ func TestDialBadOrigin(t *testing.T) {
}

func TestDialBadHeader(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Expand All @@ -448,6 +459,7 @@ func TestDialBadHeader(t *testing.T) {
}

func TestBadMethod(t *testing.T) {
t.Parallel()
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ws, err := cstUpgrader.Upgrade(w, r, nil)
if err == nil {
Expand Down Expand Up @@ -476,6 +488,7 @@ func TestBadMethod(t *testing.T) {
}

func TestDialExtraTokensInRespHeaders(t *testing.T) {
t.Parallel()
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
challengeKey := r.Header.Get("Sec-Websocket-Key")
w.Header().Set("Upgrade", "foo, websocket")
Expand All @@ -493,6 +506,7 @@ func TestDialExtraTokensInRespHeaders(t *testing.T) {
}

func TestHandshake(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Expand All @@ -519,6 +533,7 @@ func TestHandshake(t *testing.T) {
}

func TestRespOnBadHandshake(t *testing.T) {
t.Parallel()
const expectedStatus = http.StatusGone
const expectedBody = "This is the response body."

Expand Down Expand Up @@ -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.
func TestHost(t *testing.T) {
t.Parallel()

upgrader := Upgrader{}
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -745,6 +761,7 @@ func TestHost(t *testing.T) {
}

func TestDialCompression(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Expand All @@ -759,6 +776,7 @@ func TestDialCompression(t *testing.T) {
}

func TestSocksProxyDial(t *testing.T) {
t.Parallel()
s := newServer(t)
defer s.Close()

Expand Down Expand Up @@ -846,6 +864,7 @@ func TestSocksProxyDial(t *testing.T) {
}

func TestTracingDialWithContext(t *testing.T) {
t.Parallel()

var headersWrote, requestWrote, getConn, gotConn, connectDone, gotFirstResponseByte bool
trace := &httptrace.ClientTrace{
Expand Down Expand Up @@ -905,6 +924,7 @@ func TestTracingDialWithContext(t *testing.T) {
}

func TestEmptyTracingDialWithContext(t *testing.T) {
t.Parallel()

trace := &httptrace.ClientTrace{}
ctx := httptrace.WithClientTrace(context.Background(), trace)
Expand All @@ -926,6 +946,7 @@ func TestEmptyTracingDialWithContext(t *testing.T) {

// TestNetDialConnect tests selection of dial method between NetDial, NetDialContext, NetDialTLS or NetDialTLSContext
func TestNetDialConnect(t *testing.T) {
t.Parallel()

upgrader := Upgrader{}
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -1101,6 +1122,7 @@ func TestNetDialConnect(t *testing.T) {
}
}
func TestNextProtos(t *testing.T) {
t.Parallel()
ts := httptest.NewUnstartedServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}),
)
Expand Down
1 change: 1 addition & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var hostPortNoPortTests = []struct {
}

func TestHostPortNoPort(t *testing.T) {
t.Parallel()
for _, tt := range hostPortNoPortTests {
hostPort, hostNoPort := hostPortNoPort(tt.u)
if hostPort != tt.hostPort {
Expand Down
2 changes: 2 additions & 0 deletions compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type nopCloser struct{ io.Writer }
func (nopCloser) Close() error { return nil }

func TestTruncWriter(t *testing.T) {
t.Parallel()
const data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijlkmnopqrstuvwxyz987654321"
for n := 1; n <= 10; n++ {
var b bytes.Buffer
Expand Down Expand Up @@ -71,6 +72,7 @@ func BenchmarkWriteWithCompression(b *testing.B) {
}

func TestValidCompressionLevel(t *testing.T) {
t.Parallel()
c := newTestConn(nil, nil, false)
for _, level := range []int{minCompressionLevel - 1, maxCompressionLevel + 1} {
if err := c.SetCompressionLevel(level); err == nil {
Expand Down
19 changes: 19 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func newTestConn(r io.Reader, w io.Writer, isServer bool) *Conn {
}

func TestFraming(t *testing.T) {
t.Parallel()
frameSizes := []int{
0, 1, 2, 124, 125, 126, 127, 128, 129, 65534, 65535,
// 65536, 65537
Expand Down Expand Up @@ -148,6 +149,7 @@ func TestFraming(t *testing.T) {
}

func TestControl(t *testing.T) {
t.Parallel()
const message = "this is a ping/pong messsage"
for _, isServer := range []bool{true, false} {
for _, isWriteControl := range []bool{true, false} {
Expand Down Expand Up @@ -204,6 +206,7 @@ func (p *simpleBufferPool) Put(v interface{}) {
}

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."

var buf bytes.Buffer
Expand Down Expand Up @@ -282,6 +285,7 @@ func TestWriteBufferPool(t *testing.T) {

// TestWriteBufferPoolSync ensures that *sync.Pool works as a buffer pool.
func TestWriteBufferPoolSync(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
var pool sync.Pool
wc := newConn(fakeNetConn{Writer: &buf}, true, 1024, 1024, &pool, nil, nil)
Expand Down Expand Up @@ -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
// on write.
func TestWriteBufferPoolError(t *testing.T) {
t.Parallel()

// Part 1: Test NextWriter/Write/Close

Expand Down Expand Up @@ -353,6 +358,7 @@ func TestWriteBufferPoolError(t *testing.T) {
}

func TestCloseFrameBeforeFinalMessageFrame(t *testing.T) {
t.Parallel()
const bufSize = 512

expectedErr := &CloseError{Code: CloseNormalClosure, Text: "hello"}
Expand Down Expand Up @@ -385,6 +391,7 @@ func TestCloseFrameBeforeFinalMessageFrame(t *testing.T) {
}

func TestEOFWithinFrame(t *testing.T) {
t.Parallel()
const bufSize = 64

for n := 0; ; n++ {
Expand Down Expand Up @@ -422,6 +429,7 @@ func TestEOFWithinFrame(t *testing.T) {
}

func TestEOFBeforeFinalFrame(t *testing.T) {
t.Parallel()
const bufSize = 512

var b1, b2 bytes.Buffer
Expand All @@ -448,6 +456,7 @@ func TestEOFBeforeFinalFrame(t *testing.T) {
}

func TestWriteAfterMessageWriterClose(t *testing.T) {
t.Parallel()
wc := newTestConn(nil, &bytes.Buffer{}, false)
w, _ := wc.NextWriter(BinaryMessage)
if _, err := io.WriteString(w, "hello"); err != nil {
Expand Down Expand Up @@ -478,6 +487,7 @@ func TestWriteAfterMessageWriterClose(t *testing.T) {
}

func TestWriteHandlerDoesNotReturnErrCloseSent(t *testing.T) {
t.Parallel()
var b1, b2 bytes.Buffer

client := newTestConn(&b2, &b1, false)
Expand All @@ -498,6 +508,7 @@ func TestWriteHandlerDoesNotReturnErrCloseSent(t *testing.T) {
}

func TestReadLimit(t *testing.T) {
t.Parallel()
t.Run("Test ReadLimit is enforced", func(t *testing.T) {
const readLimit = 512
message := make([]byte, readLimit+1)
Expand Down Expand Up @@ -596,6 +607,7 @@ func TestReadLimit(t *testing.T) {
}

func TestAddrs(t *testing.T) {
t.Parallel()
c := newTestConn(nil, nil, true)
if c.LocalAddr() != localAddr {
t.Errorf("LocalAddr = %v, want %v", c.LocalAddr(), localAddr)
Expand All @@ -606,6 +618,7 @@ func TestAddrs(t *testing.T) {
}

func TestDeprecatedUnderlyingConn(t *testing.T) {
t.Parallel()
var b1, b2 bytes.Buffer
fc := fakeNetConn{Reader: &b1, Writer: &b2}
c := newConn(fc, true, 1024, 1024, nil, nil, nil)
Expand All @@ -616,6 +629,7 @@ func TestDeprecatedUnderlyingConn(t *testing.T) {
}

func TestNetConn(t *testing.T) {
t.Parallel()
var b1, b2 bytes.Buffer
fc := fakeNetConn{Reader: &b1, Writer: &b2}
c := newConn(fc, true, 1024, 1024, nil, nil, nil)
Expand All @@ -626,6 +640,7 @@ func TestNetConn(t *testing.T) {
}

func TestBufioReadBytes(t *testing.T) {
t.Parallel()
// Test calling bufio.ReadBytes for value longer than read buffer size.

m := make([]byte, 512)
Expand Down Expand Up @@ -668,6 +683,7 @@ var closeErrorTests = []struct {
}

func TestCloseError(t *testing.T) {
t.Parallel()
for _, tt := range closeErrorTests {
ok := IsCloseError(tt.err, tt.codes...)
if ok != tt.ok {
Expand All @@ -688,6 +704,7 @@ var unexpectedCloseErrorTests = []struct {
}

func TestUnexpectedCloseErrors(t *testing.T) {
t.Parallel()
for _, tt := range unexpectedCloseErrorTests {
ok := IsUnexpectedCloseError(tt.err, tt.codes...)
if ok != tt.ok {
Expand All @@ -709,6 +726,7 @@ func (w blockingWriter) Write(p []byte) (int, error) {
}

func TestConcurrentWritePanic(t *testing.T) {
t.Parallel()
w := blockingWriter{make(chan struct{}), make(chan struct{})}
c := newTestConn(nil, w, false)
go func() {
Expand Down Expand Up @@ -740,6 +758,7 @@ func (r failingReader) Read(p []byte) (int, error) {
}

func TestFailedConnectionReadPanic(t *testing.T) {
t.Parallel()
c := newTestConn(failingReader{}, nil, false)

defer func() {
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ func processMessage(mt int, p []byte) {}

// TestX prevents godoc from showing this entire file in the example. Remove
// this function when a second example is added.
func TestX(t *testing.T) {}
func TestX(t *testing.T) { t.Parallel() }
1 change: 1 addition & 0 deletions join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

func TestJoinMessages(t *testing.T) {
t.Parallel()
messages := []string{"a", "bc", "def", "ghij", "klmno", "0", "12", "345", "6789"}
for _, readChunk := range []int{1, 2, 3, 4, 5, 6, 7} {
for _, term := range []string{"", ","} {
Expand Down
3 changes: 3 additions & 0 deletions json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

func TestJSON(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
wc := newTestConn(nil, &buf, true)
rc := newTestConn(&buf, nil, false)
Expand All @@ -38,6 +39,7 @@ func TestJSON(t *testing.T) {
}

func TestPartialJSONRead(t *testing.T) {
t.Parallel()
var buf0, buf1 bytes.Buffer
wc := newTestConn(nil, &buf0, true)
rc := newTestConn(&buf0, &buf1, false)
Expand Down Expand Up @@ -91,6 +93,7 @@ func TestPartialJSONRead(t *testing.T) {
}

func TestDeprecatedJSON(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
wc := newTestConn(nil, &buf, true)
rc := newTestConn(&buf, nil, false)
Expand Down
1 change: 1 addition & 0 deletions mask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func notzero(b []byte) int {
}

func TestMaskBytes(t *testing.T) {
t.Parallel()
key := [4]byte{1, 2, 3, 4}
for size := 1; size <= 1024; size++ {
for align := 0; align < wordSize; align++ {
Expand Down
Loading

0 comments on commit aa1bc5b

Please sign in to comment.