Skip to content

Commit

Permalink
test: run slow tests without race detector in CI (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker authored Nov 23, 2020
1 parent 4342f3f commit 775339b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: test & coverage report creation
# Some tests, notably TestRandomOperations, are extremely slow in CI
# with the race detector enabled, so we use -short when -race is
# enabled to reduce the number of slow tests, and then run without
# -short with -race disabled for a larger test set.
#
# We still run the same tests, just on smaller data sets with -short.
run: |
go test ./... -mod=readonly -timeout 8m -race -coverprofile=coverage.txt -covermode=atomic
go test ./... -mod=readonly -timeout 5m -short -race -coverprofile=coverage.txt -covermode=atomic
go test ./... -mod=readonly -timeout 5m
- uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
Expand Down
35 changes: 19 additions & 16 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,26 @@ func TestExporter(t *testing.T) {
}

func TestExporter_Import(t *testing.T) {
testcases := map[string]struct {
tree *ImmutableTree
}{
"empty tree": {tree: NewImmutableTree(db.NewMemDB(), 0)},
"basic tree": {tree: setupExportTreeBasic(t)},
"sized tree": {tree: setupExportTreeSized(t, 4096)},
"random tree": {tree: setupExportTreeRandom(t)},
testcases := map[string]*ImmutableTree{
"empty tree": NewImmutableTree(db.NewMemDB(), 0),
"basic tree": setupExportTreeBasic(t),
}
for desc, tc := range testcases {
tc := tc // appease scopelint
if !testing.Short() {
testcases["sized tree"] = setupExportTreeSized(t, 4096)
testcases["random tree"] = setupExportTreeRandom(t)
}

for desc, tree := range testcases {
tree := tree
t.Run(desc, func(t *testing.T) {
exporter := tc.tree.Export()
t.Parallel()

exporter := tree.Export()
defer exporter.Close()

newTree, err := NewMutableTree(db.NewMemDB(), 0)
require.NoError(t, err)
importer, err := newTree.Import(tc.tree.Version())
importer, err := newTree.Import(tree.Version())
require.NoError(t, err)
defer importer.Close()

Expand All @@ -203,12 +206,12 @@ func TestExporter_Import(t *testing.T) {
require.NoError(t, err)
}

require.Equal(t, tc.tree.Hash(), newTree.Hash(), "Tree hash mismatch")
require.Equal(t, tc.tree.Size(), newTree.Size(), "Tree size mismatch")
require.Equal(t, tc.tree.Version(), newTree.Version(), "Tree version mismatch")
require.Equal(t, tree.Hash(), newTree.Hash(), "Tree hash mismatch")
require.Equal(t, tree.Size(), newTree.Size(), "Tree size mismatch")
require.Equal(t, tree.Version(), newTree.Version(), "Tree version mismatch")

tc.tree.Iterate(func(key, value []byte) bool {
index, _ := tc.tree.Get(key)
tree.Iterate(func(key, value []byte) bool {
index, _ := tree.Get(key)
newIndex, newValue := newTree.Get(key)
require.Equal(t, index, newIndex, "Index mismatch for key %v", key)
require.Equal(t, value, newValue, "Value mismatch for key %v", key)
Expand Down
10 changes: 8 additions & 2 deletions tree_random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
)

func TestRandomOperations(t *testing.T) {
// In short mode (specifically, when running in CI with the race detector),
// we only run the first couple of seeds.
seeds := []int64{
498727689,
756509998,
Expand All @@ -28,9 +30,13 @@ func TestRandomOperations(t *testing.T) {
957382170,
}

for _, seed := range seeds {
seed := seed
for i, seed := range seeds {
i, seed := i, seed
t.Run(fmt.Sprintf("Seed %v", seed), func(t *testing.T) {
if testing.Short() && i >= 2 {
t.Skip("Skipping seed in short mode")
}
t.Parallel() // comment out to disable parallel tests, or use -parallel 1
testRandomOperations(t, seed)
})
}
Expand Down

0 comments on commit 775339b

Please sign in to comment.