Skip to content

Commit

Permalink
Lower go test time
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Jun 18, 2021
1 parent 4ed933a commit 9f2c636
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 37 deletions.
4 changes: 0 additions & 4 deletions allocation_test.go
Expand Up @@ -9,8 +9,6 @@ import (
)

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

s := &Server{
Handler: func(ctx *RequestCtx) {
},
Expand Down Expand Up @@ -72,8 +70,6 @@ func TestAllocationClient(t *testing.T) {
}

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

uri := []byte("http://username:password@example.com/some/path?foo=bar#test")

n := testing.AllocsPerRun(100, func() {
Expand Down
37 changes: 18 additions & 19 deletions client_test.go
Expand Up @@ -21,6 +21,8 @@ import (
)

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

ln := fasthttputil.NewInmemoryListener()

s := &Server{
Expand Down Expand Up @@ -278,10 +280,7 @@ func TestClientURLAuth(t *testing.T) {
}

func TestClientNilResp(t *testing.T) {
// For some reason running this test in parallel sometimes
// triggers the race checker. I have not been able to find an
// actual race condition so I think it's something else going wrong.
// For now just don't run this test in parallel.
t.Parallel()

ln := fasthttputil.NewInmemoryListener()
s := &Server{
Expand All @@ -303,6 +302,7 @@ func TestClientNilResp(t *testing.T) {
if err := c.DoTimeout(req, nil, time.Second); err != nil {
t.Fatal(err)
}
ln.Close()
}

func TestPipelineClientNilResp(t *testing.T) {
Expand Down Expand Up @@ -627,19 +627,13 @@ func TestClientHeaderCase(t *testing.T) {
func TestClientReadTimeout(t *testing.T) {
t.Parallel()

// This test is rather slow and increase the total test time
// from 2.5 seconds to 6.5 seconds.
if testing.Short() {
t.Skip("skipping test in short mode")
}

ln := fasthttputil.NewInmemoryListener()

timeout := false
s := &Server{
Handler: func(ctx *RequestCtx) {
if timeout {
time.Sleep(time.Minute)
time.Sleep(time.Second)
} else {
timeout = true
}
Expand All @@ -649,7 +643,7 @@ func TestClientReadTimeout(t *testing.T) {
go s.Serve(ln) //nolint:errcheck

c := &HostClient{
ReadTimeout: time.Second * 4,
ReadTimeout: time.Millisecond * 400,
MaxIdemponentCallAttempts: 1,
Dial: func(addr string) (net.Conn, error) {
return ln.Dial()
Expand Down Expand Up @@ -692,8 +686,8 @@ func TestClientReadTimeout(t *testing.T) {
select {
case <-done:
// This shouldn't take longer than the timeout times the number of requests it is going to try to do.
// Give it 2 seconds extra seconds just to be sure.
case <-time.After(c.ReadTimeout*time.Duration(c.MaxIdemponentCallAttempts) + time.Second*2):
// Give it an extra second just to be sure.
case <-time.After(c.ReadTimeout*time.Duration(c.MaxIdemponentCallAttempts) + time.Second):
t.Fatal("Client.ReadTimeout didn't work")
}
}
Expand Down Expand Up @@ -1282,6 +1276,8 @@ func TestHostClientPendingRequests(t *testing.T) {
}

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

var (
emptyBodyCount uint8
ln = fasthttputil.NewInmemoryListener()
Expand Down Expand Up @@ -2515,9 +2511,6 @@ func startEchoServerExt(t *testing.T, network, addr string, isTLS bool) *testEch
func TestClientTLSHandshakeTimeout(t *testing.T) {
t.Parallel()

if testing.Short() {
t.Skip("skipping test in short mode")
}
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
Expand All @@ -2540,8 +2533,8 @@ func TestClientTLSHandshakeTimeout(t *testing.T) {
}()

client := Client{
WriteTimeout: 1 * time.Second,
ReadTimeout: 1 * time.Second,
WriteTimeout: 100 * time.Millisecond,
ReadTimeout: 100 * time.Millisecond,
}

_, _, err = client.Get(nil, "https://"+addr)
Expand All @@ -2555,6 +2548,8 @@ func TestClientTLSHandshakeTimeout(t *testing.T) {
}

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

var (
emptyBodyCount uint8
ln = fasthttputil.NewInmemoryListener()
Expand Down Expand Up @@ -2632,6 +2627,8 @@ func TestHostClientMaxConnWaitTimeoutSuccess(t *testing.T) {
}

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

var (
emptyBodyCount uint8
ln = fasthttputil.NewInmemoryListener()
Expand Down Expand Up @@ -2720,6 +2717,8 @@ func TestHostClientMaxConnWaitTimeoutError(t *testing.T) {
}

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

var (
emptyBodyCount uint8
ln = fasthttputil.NewInmemoryListener()
Expand Down
2 changes: 2 additions & 0 deletions cookie_test.go
Expand Up @@ -7,6 +7,8 @@ import (
)

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

var c Cookie
if err := c.Parse(";SAMeSITe="); err != nil {
t.Error(err)
Expand Down
2 changes: 2 additions & 0 deletions expvarhandler/expvar_test.go
Expand Up @@ -10,6 +10,8 @@ import (
)

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

expvar.Publish("customVar", expvar.Func(func() interface{} {
return "foobar"
}))
Expand Down
4 changes: 4 additions & 0 deletions fasthttpadaptor/adaptor_test.go
Expand Up @@ -13,6 +13,8 @@ import (
)

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

expectedMethod := fasthttp.MethodPost
expectedProto := "HTTP/1.1"
expectedProtoMajor := 1
Expand Down Expand Up @@ -141,6 +143,8 @@ func setContextValueMiddleware(next fasthttp.RequestHandler, key string, value i
}

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

nethttpH := func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("<!doctype html><html>")) //nolint:errcheck
}
Expand Down
8 changes: 8 additions & 0 deletions fasthttputil/inmemory_listener_test.go
Expand Up @@ -14,6 +14,8 @@ import (
)

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

ln := NewInmemoryListener()

ch := make(chan struct{})
Expand Down Expand Up @@ -156,12 +158,16 @@ func testInmemoryListenerHTTPSingle(t *testing.T, client *http.Client, content s
}

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

testInmemoryListenerHTTP(t, func(t *testing.T, client *http.Client) {
testInmemoryListenerHTTPSingle(t, client, "request")
})
}

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

testInmemoryListenerHTTP(t, func(t *testing.T, client *http.Client) {
for i := 0; i < 10; i++ {
testInmemoryListenerHTTPSingle(t, client, fmt.Sprintf("request_%d", i))
Expand All @@ -170,6 +176,8 @@ func TestInmemoryListenerHTTPSerial(t *testing.T) {
}

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

testInmemoryListenerHTTP(t, func(t *testing.T, client *http.Client) {
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
Expand Down
18 changes: 18 additions & 0 deletions fasthttputil/pipeconns_test.go
Expand Up @@ -11,6 +11,8 @@ import (
)

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

pc := NewPipeConns()
c1 := pc.Conn1()

Expand Down Expand Up @@ -67,10 +69,14 @@ func TestPipeConnsWriteTimeout(t *testing.T) {
}

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

testPipeConnsReadTimeout(t, time.Millisecond)
}

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

testPipeConnsReadTimeout(t, -time.Second)
}

Expand Down Expand Up @@ -116,6 +122,8 @@ func testPipeConnsReadTimeout(t *testing.T, timeout time.Duration) {
}

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

concurrency := 4
ch := make(chan struct{}, concurrency)
for i := 0; i < concurrency; i++ {
Expand All @@ -135,6 +143,8 @@ func TestPipeConnsCloseWhileReadWriteConcurrent(t *testing.T) {
}

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

testPipeConnsCloseWhileReadWriteSerial(t)
}

Expand Down Expand Up @@ -205,10 +215,14 @@ func testPipeConnsCloseWhileReadWrite(t *testing.T) {
}

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

testPipeConnsReadWriteSerial(t)
}

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

testConcurrency(t, 10, testPipeConnsReadWriteSerial)
}

Expand Down Expand Up @@ -262,10 +276,14 @@ func testPipeConnsReadWrite(t *testing.T, c1, c2 net.Conn) {
}

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

testPipeConnsCloseSerial(t)
}

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

testConcurrency(t, 10, testPipeConnsCloseSerial)
}

Expand Down
10 changes: 6 additions & 4 deletions fs_test.go
Expand Up @@ -50,6 +50,8 @@ func TestNewVHostPathRewriter(t *testing.T) {
}

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

var ctx RequestCtx
var req Request
req.Header.SetHost("/../../../etc/passwd")
Expand Down Expand Up @@ -301,7 +303,7 @@ func TestServeFileUncompressed(t *testing.T) {
}

func TestFSByteRangeConcurrent(t *testing.T) {
t.Parallel()
// This test can't run parallel as files in / might by changed by other tests.

stop := make(chan struct{})
defer close(stop)
Expand Down Expand Up @@ -335,7 +337,7 @@ func TestFSByteRangeConcurrent(t *testing.T) {
}

func TestFSByteRangeSingleThread(t *testing.T) {
t.Parallel()
// This test can't run parallel as files in / might by changed by other tests.

stop := make(chan struct{})
defer close(stop)
Expand Down Expand Up @@ -818,12 +820,12 @@ func TestServeFileContentType(t *testing.T) {
}

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

if runtime.GOOS == "windows" {
t.SkipNow()
}

t.Parallel()

var ctx RequestCtx
var req Request
req.SetRequestURI("http://foobar.com")
Expand Down

0 comments on commit 9f2c636

Please sign in to comment.