mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-19 21:56:22 +00:00
Improve handling of -short flag in tests (#9075)
As a small developer quality of life improvement, I found many individual unit tests that take longer than around a second to complete, and set them to skip when run under `go test -short`. On my machine, the wall timings for tests (with `go test -count=1 ./...` and optionally `-short` and `-race`) are roughly: - Long tests, no race detector: about 1m42s - Short tests, no race detector: about 17s - Long tests, race detector enabled: about 2m1s - Short tests, race detector enabled: about 28s This PR is split into many commits each touching a single package, with commit messages detailing the approximate timing change per package.
This commit is contained in:
@@ -18,6 +18,10 @@ import (
|
||||
)
|
||||
|
||||
func TestHTTPSimple(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
@@ -68,6 +72,10 @@ func TestHTTPSimple(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHTTPBatching(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -15,6 +15,10 @@ import (
|
||||
)
|
||||
|
||||
func TestWaitForHeight(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -133,6 +133,10 @@ func TestClientOperations(t *testing.T) {
|
||||
})
|
||||
t.Run("Batching", func(t *testing.T) {
|
||||
t.Run("JSONRPCCalls", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
logger := log.NewTestingLogger(t)
|
||||
c := getHTTPClient(t, logger, conf)
|
||||
testBatchedJSONRPCCalls(ctx, t, c)
|
||||
@@ -171,6 +175,10 @@ func TestClientOperations(t *testing.T) {
|
||||
require.Zero(t, batch.Clear(), "clearing an empty batch of JSON RPC requests should result in a 0 result")
|
||||
})
|
||||
t.Run("ConcurrentJSONRPC", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
logger := log.NewTestingLogger(t)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
@@ -291,6 +299,10 @@ func TestClientMethodCalls(t *testing.T) {
|
||||
"first: %+v, doc: %s", first, string(doc))
|
||||
})
|
||||
t.Run("ABCIQuery", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
// write something
|
||||
k, v, tx := MakeTxKV()
|
||||
status, err := c.Status(ctx)
|
||||
@@ -309,6 +321,10 @@ func TestClientMethodCalls(t *testing.T) {
|
||||
}
|
||||
})
|
||||
t.Run("AppCalls", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
// get an offset of height to avoid racing and guessing
|
||||
s, err := c.Status(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -409,6 +425,10 @@ func TestClientMethodCalls(t *testing.T) {
|
||||
// XXX Test proof
|
||||
})
|
||||
t.Run("BlockchainInfo", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
@@ -439,6 +459,10 @@ func TestClientMethodCalls(t *testing.T) {
|
||||
assert.Contains(t, err.Error(), "can't be greater than max")
|
||||
})
|
||||
t.Run("BroadcastTxCommit", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
_, _, tx := MakeTxKV()
|
||||
bres, err := c.BroadcastTxCommit(ctx, tx)
|
||||
require.NoError(t, err, "%d: %+v", i, err)
|
||||
@@ -481,6 +505,10 @@ func TestClientMethodCalls(t *testing.T) {
|
||||
// TODO: more checks...
|
||||
})
|
||||
t.Run("Block", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
const subscriber = "TestBlockEvents"
|
||||
|
||||
eventCh, err := c.Subscribe(ctx, subscriber, types.QueryForEvent(types.EventNewBlockValue).String())
|
||||
@@ -515,6 +543,10 @@ func TestClientMethodCalls(t *testing.T) {
|
||||
})
|
||||
t.Run("Evidence", func(t *testing.T) {
|
||||
t.Run("BroadcastDuplicateVote", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
@@ -722,6 +754,10 @@ func TestClientMethodCallsAdvanced(t *testing.T) {
|
||||
}
|
||||
})
|
||||
t.Run("TxSearchWithTimeout", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
logger := log.NewTestingLogger(t)
|
||||
|
||||
timeoutClient := getHTTPClientWithTimeout(t, logger, conf, 10*time.Second)
|
||||
|
||||
@@ -65,6 +65,10 @@ func (h *myTestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func TestWSClientReconnectsAfterReadFailure(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
t.Cleanup(leaktest.Check(t))
|
||||
|
||||
// start server
|
||||
@@ -97,6 +101,10 @@ func TestWSClientReconnectsAfterReadFailure(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWSClientReconnectsAfterWriteFailure(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
t.Cleanup(leaktest.Check(t))
|
||||
|
||||
// start server
|
||||
@@ -127,6 +135,10 @@ func TestWSClientReconnectsAfterWriteFailure(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWSClientReconnectFailure(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
t.Cleanup(leaktest.Check(t))
|
||||
|
||||
// start server
|
||||
|
||||
@@ -340,6 +340,10 @@ func TestRPC(t *testing.T) {
|
||||
}
|
||||
})
|
||||
t.Run("WSClientPingPong", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
// TestWSClientPingPong checks that a client & server exchange pings
|
||||
// & pongs so connection stays alive.
|
||||
t.Cleanup(leaktest.CheckTimeout(t, 4*time.Second))
|
||||
|
||||
Reference in New Issue
Block a user