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
+16
View File
@@ -16,6 +16,10 @@ const (
)
func TestBasicPartSet(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
// Construct random data of size partSize * 100
nParts := 100
data := tmrand.Bytes(testPartSize * nParts)
@@ -64,6 +68,10 @@ func TestBasicPartSet(t *testing.T) {
}
func TestWrongProof(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
// Construct random data of size partSize * 100
data := tmrand.Bytes(testPartSize * 100)
partSet := NewPartSetFromData(data, testPartSize)
@@ -89,6 +97,10 @@ func TestWrongProof(t *testing.T) {
}
func TestPartSetHeaderValidateBasic(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
testCases := []struct {
testName string
malleatePartSetHeader func(*PartSetHeader)
@@ -110,6 +122,10 @@ func TestPartSetHeaderValidateBasic(t *testing.T) {
}
func TestPartValidateBasic(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
testCases := []struct {
testName string
malleatePart func(*Part)
+4
View File
@@ -1207,6 +1207,10 @@ func applyChangesToValSet(t *testing.T, expErr error, valSet *ValidatorSet, vals
}
func TestValSetUpdatePriorityOrderTests(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
const nMaxElections int32 = 5000
testCases := []testVSetCfg{