Update TestMain(): do not call os.Exit() explicitly (#8046)

* update workspace

* update testmain
This commit is contained in:
Victor Farazdagi
2020-12-04 19:10:07 +03:00
committed by GitHub
parent ccba8cfa5a
commit be078d6a16
20 changed files with 124 additions and 203 deletions

View File

@@ -2,18 +2,14 @@ package blockchain
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -1,17 +1,13 @@
package cache
import (
"os"
"testing"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
)
func TestMain(m *testing.M) {
run := func() int {
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{EnableEth1DataVoteCache: true})
defer resetCfg()
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -1,21 +1,17 @@
package spectest
import (
"os"
"testing"
"github.com/prysmaticlabs/prysm/shared/params"
)
func TestMain(m *testing.M) {
run := func() int {
prevConfig := params.BeaconConfig().Copy()
defer params.OverrideBeaconConfig(prevConfig)
c := params.BeaconConfig()
c.MinGenesisActiveValidatorCount = 16384
params.OverrideBeaconConfig(c)
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -2,7 +2,6 @@ package peers_test
import (
"io/ioutil"
"os"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
@@ -11,7 +10,6 @@ import (
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
@@ -28,7 +26,5 @@ func TestMain(m *testing.M) {
defer func() {
flags.Init(resetFlags)
}()
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -3,7 +3,6 @@ package scorers_test
import (
"io/ioutil"
"math"
"os"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
@@ -13,7 +12,6 @@ import (
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
@@ -30,9 +28,7 @@ func TestMain(m *testing.M) {
defer func() {
flags.Init(resetFlags)
}()
return m.Run()
}
os.Exit(run())
m.Run()
}
// roundScore returns score rounded in accordance with the score manager's rounding factor.

View File

@@ -2,18 +2,14 @@ package powchain
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -1,7 +1,6 @@
package beacon
import (
"os"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
@@ -9,7 +8,6 @@ import (
)
func TestMain(m *testing.M) {
run := func() int {
// Use minimal config to reduce test setup time.
prevConfig := params.BeaconConfig().Copy()
defer params.OverrideBeaconConfig(prevConfig)
@@ -23,7 +21,5 @@ func TestMain(m *testing.M) {
flags.Init(resetFlags)
}()
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -2,7 +2,6 @@ package validator
import (
"io/ioutil"
"os"
"testing"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -10,7 +9,6 @@ import (
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
// Use minimal config to reduce test setup time.
@@ -18,7 +16,5 @@ func TestMain(m *testing.M) {
defer params.OverrideBeaconConfig(prevConfig)
params.OverrideBeaconConfig(params.MinimalSpecConfig())
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -1,17 +1,13 @@
package stateutil_test
import (
"os"
"testing"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
)
func TestMain(m *testing.M) {
run := func() int {
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{EnableSSZCache: true})
defer resetCfg()
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io/ioutil"
"os"
"sync"
"testing"
"time"
@@ -53,7 +52,6 @@ type peerData struct {
}
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
@@ -71,9 +69,7 @@ func TestMain(m *testing.M) {
flags.Init(resetFlags)
}()
return m.Run()
}
os.Exit(run())
m.Run()
}
func initializeTestServices(t *testing.T, blocks []uint64, peers []*peerData) (*mock.ChainService, *p2pt.TestP2P, db.Database) {

View File

@@ -2,7 +2,6 @@ package sync
import (
"io/ioutil"
"os"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
@@ -10,7 +9,6 @@ import (
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
@@ -22,7 +20,5 @@ func TestMain(m *testing.M) {
defer func() {
flags.Init(resetFlags)
}()
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -3,7 +3,6 @@ package attestations
import (
"fmt"
"io/ioutil"
"os"
"sort"
"testing"
@@ -20,16 +19,13 @@ import (
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
AttestationAggregationStrategy: string(MaxCoverAggregation),
})
defer resetCfg()
return m.Run()
}
os.Exit(run())
m.Run()
}
func TestAggregateAttestations_AggregatePair(t *testing.T) {

View File

@@ -2,18 +2,14 @@ package slotutil
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -2,7 +2,6 @@ package beaconclient
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
@@ -14,11 +13,8 @@ var (
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -2,7 +2,6 @@ package kv
import (
"io/ioutil"
"os"
"testing"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
@@ -10,13 +9,10 @@ import (
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
return m.Run()
}
os.Exit(run())
m.Run()
}
func setupDB(t testing.TB) *Store {

View File

@@ -2,18 +2,14 @@ package attestations
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -2,18 +2,14 @@ package proposals
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -16,13 +16,10 @@ import (
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
return m.Run()
}
os.Exit(run())
m.Run()
}
// Test that slasher node can close.

View File

@@ -2,18 +2,14 @@ package rpc
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
return m.Run()
}
os.Exit(run())
m.Run()
}

View File

@@ -5,7 +5,6 @@ import (
"crypto/rand"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
@@ -20,13 +19,10 @@ import (
)
func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
return m.Run()
}
os.Exit(run())
m.Run()
}
func TestBootnode_OK(t *testing.T) {