Skip to content

Commit

Permalink
chore(all): move long tests to integration tests (#2887)
Browse files Browse the repository at this point in the history
- Move test files with >75% long tests to integration-tagged-and-named test files
- Add package names to the integration tests CI workflow matrix
- Remove usage of `t.Short()` + skip `Test_Gossip` since it doesn't work
- Move `//go:generate` commands to non-integration-tagged test files to avoid passing `-tags integration` to `go generate`
- Remove older `// +build integration`
- Remove average coverage targets in codecov configuration
  • Loading branch information
qdm12 authored Nov 23, 2022
1 parent e1ed7ed commit 1ec0f63
Show file tree
Hide file tree
Showing 59 changed files with 1,238 additions and 1,240 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ For coding style, you may refer to the [code style](CODE_STYLE.md) document whic
⚠️ We are still using `mockery` instead of `gomock` for older mocks, so you need to run `go generate -run "mockery|mockgen" ./...` to update all the existing mocks. We are slowly migrating our mocks and test code to use `gomock`.
> To execute `//go:generate` commands that are placed at files with `// +build integration` remember to add `-tags integration` in the `go generate` command eg. `go generate -tags integration ...`
> To execute `//go:generate` commands that are placed at files with `//go:build integration` remember to add `-tags integration` in the `go generate` command eg. `go generate -tags integration ...`
9. **Lint your changes.**
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
- name: Generate coverage report
run: |
go test ./... -short -coverprofile=coverage.out -covermode=atomic -timeout=20m
go test ./... -coverprofile=coverage.out -covermode=atomic -timeout=20m
- uses: codecov/[email protected]
with:
files: ./coverage.out
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ jobs:
[
github.com/ChainSafe/gossamer/dot,
github.com/ChainSafe/gossamer/dot/core,
github.com/ChainSafe/gossamer/dot/rpc,
github.com/ChainSafe/gossamer/dot/rpc/modules,
github.com/ChainSafe/gossamer/lib/babe,
github.com/ChainSafe/gossamer/dot/rpc/subscription,
github.com/ChainSafe/gossamer/dot/state,
github.com/ChainSafe/gossamer/dot/digest,
github.com/ChainSafe/gossamer/dot/network,
github.com/ChainSafe/gossamer/dot/sync,
github.com/ChainSafe/gossamer/lib/babe,
github.com/ChainSafe/gossamer/lib/grandpa,
]
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
cd ..
- name: Run unit tests
run: go test -short -coverprofile=coverage.out -covermode=atomic -timeout=45m ./...
run: go test -coverprofile=coverage.out -covermode=atomic -timeout=45m ./...

- name: Test State - Race
run: make test-state-race
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ proto:
test:
@echo " > \033[32mRunning tests...\033[0m "
git lfs pull
go test -short -coverprofile c.out ./... -timeout=30m
go test -coverprofile c.out ./... -timeout=30m

## it-stress: Runs Integration Tests stress mode
it-stress: build
@echo " > \033[32mRunning stress tests...\033[0m "
MODE=stress go test ./tests/stress/... -timeout=15m -v -short -run TestSync_
MODE=stress go test ./tests/stress/... -timeout=15m -v -run TestSync_

it-grandpa: build
@echo " > \033[32mRunning GRANDPA stress tests...\033[0m "
Expand All @@ -60,7 +60,7 @@ it-polkadotjs: build
## test: Runs `go test -race` on project test files.
test-state-race:
@echo " > \033[32mRunning race tests...\033[0m "
go test ./dot/state/... -short -race -timeout=5m
go test ./dot/state/... -race -timeout=5m

## deps: Install missing dependencies. Runs `go mod download` internally.
deps:
Expand Down
59 changes: 2 additions & 57 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,9 @@ coverage:
patch: off
project:
default:
target: 60%
# Only require global coverage to be 60%
# to allow room for refactors
90pc:
target: 90%
paths:
- "internal"
- "internal/log"
- "internal/pprof"
- "internal/trie"
80pc:
target: 80%
paths:
- "dot/rpc"
- "dot/system"
- "dot/telemetry"
- "internal/httpserver"
- "lib/services"
70pc:
target: 70%
paths:
- "pkg"
- "pkg/scale"
- "lib/runtime/offchain"
- "lib/transaction"
- "lib/trie"
60pc:
target: 60%
paths:
- "dot"
- "dot/core"
- "dot/digest"
- "dot/network"
- "dot/peerset"
- "dot/sync"
- "lib/grandpa"
- "lib/blocktree"
50pc:
target: 50%
paths:
- "cmd"
- "cmd/gossamer"
- "lib"
- "lib/crypto"
- "lib/runtime"
- "lib/runtime/wasmer"
- "lib/runtime/storage"
- "lib/babe"
33pc:
target: 33%
paths:
- "dot/state"
- "dot/types"
- "lib/common"
- "lib/utils"
- "lib/genesis"
- "lib/keystore"
- "lib/genesis"
# Only require global coverage to be 50%
# to allow room for refactors

comment:
layout: diff
Expand Down
1 change: 1 addition & 0 deletions dot/core/mocks_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
package core

//go:generate mockgen -destination=mocks_test.go -package $GOPACKAGE . BlockState,StorageState,TransactionState,Network,EpochState,CodeSubstitutedState,RuntimeInstance
//go:generate mockgen -destination=mock_telemetry_test.go -package $GOPACKAGE github.com/ChainSafe/gossamer/dot/telemetry Client
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integration

// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

Expand All @@ -22,9 +24,6 @@ import (
"github.com/stretchr/testify/require"
)

//go:generate mockgen -destination=mock_telemetry_test.go -package $GOPACKAGE github.com/ChainSafe/gossamer/dot/telemetry Client
//go:generate mockgen -destination=mock_grandpa_test.go -package $GOPACKAGE . GrandpaState

func newTestHandler(t *testing.T) (*Handler, *state.Service) {
testDatadirPath := t.TempDir()

Expand Down
7 changes: 7 additions & 0 deletions dot/digest/mocks_generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2022 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package digest

//go:generate mockgen -destination=mock_telemetry_test.go -package $GOPACKAGE github.com/ChainSafe/gossamer/dot/telemetry Client
//go:generate mockgen -destination=mock_grandpa_test.go -package $GOPACKAGE . GrandpaState
104 changes: 97 additions & 7 deletions dot/import_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package dot

import (
"errors"
"os"
"testing"

Expand All @@ -14,16 +15,48 @@ import (
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/pkg/scale"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNewTrieFromPairs(t *testing.T) {
fp := setupStateFile(t)
trie, err := newTrieFromPairs(fp)
require.NoError(t, err)

expectedRoot := common.MustHexToHash("0x09f9ca28df0560c2291aa16b56e15e07d1e1927088f51356d522722aa90ca7cb")
require.Equal(t, expectedRoot, trie.MustHash())
func Test_newTrieFromPairs(t *testing.T) {
t.Parallel()

tests := []struct {
name string
filename string
want common.Hash
err error
}{
{
name: "no arguments",
err: errors.New("read .: is a directory"),
want: common.Hash{},
},
{
name: "working example",
filename: setupStateFile(t),
want: common.MustHexToHash("0x09f9ca28df0560c2291aa16b56e15e07d1e1927088f51356d522722aa90ca7cb"),
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

got, err := newTrieFromPairs(tt.filename)
if tt.err != nil {
assert.EqualError(t, err, tt.err.Error())
} else {
assert.NoError(t, err)
}
if tt.want.IsEmpty() {
assert.Nil(t, got)
} else {
assert.Equal(t, tt.want, got.MustHash())
}
})
}
}

func TestNewHeaderFromFile(t *testing.T) {
Expand Down Expand Up @@ -81,3 +114,60 @@ func TestImportState_Integration(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, data)
}

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

basepath := t.TempDir()

cfg := NewTestConfig(t)

cfg.Init.Genesis = NewTestGenesisRawFile(t, cfg)

cfg.Global.BasePath = basepath
nodeInstance := nodeBuilder{}
err := nodeInstance.initNode(cfg)
require.NoError(t, err)

stateFP := setupStateFile(t)
headerFP := setupHeaderFile(t)

type args struct {
basepath string
stateFP string
headerFP string
firstSlot uint64
}
tests := []struct {
name string
args args
err error
}{
{
name: "no arguments",
err: errors.New("read .: is a directory"),
},
{
name: "working example",
args: args{
basepath: basepath,
stateFP: stateFP,
headerFP: headerFP,
firstSlot: 262493679,
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

err := ImportState(tt.args.basepath, tt.args.stateFP, tt.args.headerFP, tt.args.firstSlot)
if tt.err != nil {
assert.EqualError(t, err, tt.err.Error())
} else {
assert.NoError(t, err)
}
})
}
}
97 changes: 0 additions & 97 deletions dot/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,63 +64,6 @@ func setupHeaderFile(t *testing.T) string {
return fp
}

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

basepath := t.TempDir()

cfg := NewTestConfig(t)

cfg.Init.Genesis = NewTestGenesisRawFile(t, cfg)

cfg.Global.BasePath = basepath
nodeInstance := nodeBuilder{}
err := nodeInstance.initNode(cfg)
require.NoError(t, err)

stateFP := setupStateFile(t)
headerFP := setupHeaderFile(t)

type args struct {
basepath string
stateFP string
headerFP string
firstSlot uint64
}
tests := []struct {
name string
args args
err error
}{
{
name: "no arguments",
err: errors.New("read .: is a directory"),
},
{
name: "working example",
args: args{
basepath: basepath,
stateFP: stateFP,
headerFP: headerFP,
firstSlot: 262493679,
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

err := ImportState(tt.args.basepath, tt.args.stateFP, tt.args.headerFP, tt.args.firstSlot)
if tt.err != nil {
assert.EqualError(t, err, tt.err.Error())
} else {
assert.NoError(t, err)
}
})
}
}

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

Expand Down Expand Up @@ -196,43 +139,3 @@ func Test_newHeaderFromFile(t *testing.T) {
})
}
}

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

tests := []struct {
name string
filename string
want common.Hash
err error
}{
{
name: "no arguments",
err: errors.New("read .: is a directory"),
want: common.Hash{},
},
{
name: "working example",
filename: setupStateFile(t),
want: common.MustHexToHash("0x09f9ca28df0560c2291aa16b56e15e07d1e1927088f51356d522722aa90ca7cb"),
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

got, err := newTrieFromPairs(tt.filename)
if tt.err != nil {
assert.EqualError(t, err, tt.err.Error())
} else {
assert.NoError(t, err)
}
if tt.want.IsEmpty() {
assert.Nil(t, got)
} else {
assert.Equal(t, tt.want, got.MustHash())
}
})
}
}
Loading

0 comments on commit 1ec0f63

Please sign in to comment.