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:
Mark Rushakoff
2022-07-29 13:41:54 +00:00
committed by GitHub
parent 48147e1fb9
commit d433ebe68d
24 changed files with 217 additions and 2 deletions
+4
View File
@@ -235,6 +235,10 @@ func TestLightClientAttackEvidence_Equivocation(t *testing.T) {
}
func TestLightClientAttackEvidence_ForwardLunatic(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
// primary performs a lunatic attack but changes the time of the header to
// something in the future relative to the blockchain
var (
+4
View File
@@ -17,6 +17,10 @@ import (
// Manually getting light blocks and verifying them.
func TestExampleClient(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conf, err := rpctest.CreateConfig(t, "ExampleClient_VerifyLightBlockAtHeight")
+12
View File
@@ -23,6 +23,10 @@ import (
// Automatically getting new headers and verifying them.
func TestClientIntegration_Update(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
@@ -84,6 +88,10 @@ func TestClientIntegration_Update(t *testing.T) {
// Manually getting light blocks and verifying them.
func TestClientIntegration_VerifyLightBlockAtHeight(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -162,6 +170,10 @@ func waitForBlock(ctx context.Context, p provider.Provider, height int64) (*type
}
func TestClientStatusRPC(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conf, err := rpctest.CreateConfig(t, t.Name())
+4
View File
@@ -33,6 +33,10 @@ func TestNewProvider(t *testing.T) {
}
func TestProvider(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg, err := rpctest.CreateConfig(t, t.Name())