Remove redundant calls to os.exit() in TestMain (#7761)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Victor Farazdagi
2020-11-10 17:56:47 +03:00
committed by GitHub
parent 7b0ee3adfe
commit 09e3f0360e
22 changed files with 35 additions and 74 deletions

View File

@@ -57,7 +57,7 @@ go_test(
"checkpoint_state_test.go",
"committee_fuzz_test.go",
"committee_test.go",
"feature_flag_test.go",
"cache_test.go",
"hot_state_cache_test.go",
"skip_slot_cache_test.go",
"subnet_ids_test.go",

View File

@@ -1,7 +1,6 @@
package cache
import (
"os"
"testing"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
@@ -10,8 +9,5 @@ import (
func TestMain(m *testing.M) {
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{EnableEth1DataVoteCache: true})
defer resetCfg()
code := m.Run()
// os.Exit will prevent defer from being called
resetCfg()
os.Exit(code)
m.Run()
}

View File

@@ -1,7 +1,6 @@
package spectest
import (
"os"
"testing"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -9,11 +8,10 @@ import (
func TestMain(m *testing.M) {
prevConfig := params.BeaconConfig().Copy()
defer params.OverrideBeaconConfig(prevConfig)
c := params.BeaconConfig()
c.MinGenesisActiveValidatorCount = 16384
params.OverrideBeaconConfig(c)
retVal := m.Run()
params.OverrideBeaconConfig(prevConfig)
os.Exit(retVal)
m.Run()
}

View File

@@ -2,7 +2,6 @@ package peers_test
import (
"io/ioutil"
"os"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
@@ -27,9 +26,5 @@ func TestMain(m *testing.M) {
defer func() {
flags.Init(resetFlags)
}()
code := m.Run()
// os.Exit will prevent defer from being called
resetCfg()
flags.Init(resetFlags)
os.Exit(code)
m.Run()
}

View File

@@ -3,7 +3,6 @@ package scorers_test
import (
"io/ioutil"
"math"
"os"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
@@ -29,11 +28,7 @@ func TestMain(m *testing.M) {
defer func() {
flags.Init(resetFlags)
}()
code := m.Run()
// os.Exit will prevent defer from being called
resetCfg()
flags.Init(resetFlags)
os.Exit(code)
m.Run()
}
// roundScore returns score rounded in accordance with the score manager's rounding factor.

View File

@@ -2,7 +2,6 @@ package powchain
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
@@ -12,5 +11,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
os.Exit(m.Run())
m.Run()
}

View File

@@ -1,7 +1,6 @@
package beacon
import (
"os"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
@@ -11,14 +10,16 @@ import (
func TestMain(m *testing.M) {
// Use minimal config to reduce test setup time.
prevConfig := params.BeaconConfig().Copy()
defer params.OverrideBeaconConfig(prevConfig)
params.OverrideBeaconConfig(params.MinimalSpecConfig())
resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
MinimumSyncPeers: 30,
})
defer func() {
flags.Init(resetFlags)
}()
retVal := m.Run()
// Reset configuration.
params.OverrideBeaconConfig(prevConfig)
os.Exit(retVal)
m.Run()
}

View File

@@ -2,7 +2,6 @@ package validator
import (
"io/ioutil"
"os"
"testing"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -14,11 +13,8 @@ func TestMain(m *testing.M) {
logrus.SetOutput(ioutil.Discard)
// Use minimal config to reduce test setup time.
prevConfig := params.BeaconConfig().Copy()
defer params.OverrideBeaconConfig(prevConfig)
params.OverrideBeaconConfig(params.MinimalSpecConfig())
retVal := m.Run()
// Reset configuration.
params.OverrideBeaconConfig(prevConfig)
os.Exit(retVal)
m.Run()
}

View File

@@ -1,7 +1,6 @@
package stateutil_test
import (
"os"
"testing"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
@@ -10,8 +9,5 @@ import (
func TestMain(m *testing.M) {
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{EnableSSZCache: true})
defer resetCfg()
code := m.Run()
// os.Exit will prevent defer from being called
resetCfg()
os.Exit(code)
m.Run()
}

View File

@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io/ioutil"
"os"
"sync"
"testing"
"time"
@@ -69,11 +68,8 @@ func TestMain(m *testing.M) {
defer func() {
flags.Init(resetFlags)
}()
code := m.Run()
// os.Exit will prevent defer from being called
resetCfg()
flags.Init(resetFlags)
os.Exit(code)
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"
@@ -13,10 +12,14 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
BlockBatchLimit: 64,
BlockBatchLimitBurstFactor: 10,
})
defer func() {
flags.Init(resetFlags)
}()
os.Exit(m.Run())
m.Run()
}

View File

@@ -3,7 +3,6 @@ package attestations
import (
"fmt"
"io/ioutil"
"os"
"sort"
"testing"
@@ -26,10 +25,7 @@ func TestMain(m *testing.M) {
AttestationAggregationStrategy: string(MaxCoverAggregation),
})
defer resetCfg()
code := m.Run()
// os.Exit will prevent defer from being called
resetCfg()
os.Exit(code)
m.Run()
}
func TestAggregateAttestations_AggregatePair(t *testing.T) {

View File

@@ -2,7 +2,6 @@ package slotutil
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
@@ -12,5 +11,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
os.Exit(m.Run())
m.Run()
}

View File

@@ -2,7 +2,6 @@ package beaconclient
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
@@ -17,5 +16,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
os.Exit(m.Run())
m.Run()
}

View File

@@ -18,7 +18,7 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
os.Exit(m.Run())
m.Run()
}
func setupDB(t testing.TB) *Store {

View File

@@ -2,7 +2,6 @@ package attestations
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
@@ -12,5 +11,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
os.Exit(m.Run())
m.Run()
}

View File

@@ -2,7 +2,6 @@ package proposals
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
@@ -12,5 +11,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
os.Exit(m.Run())
m.Run()
}

View File

@@ -22,7 +22,7 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
os.Exit(m.Run())
m.Run()
}
// Test that slasher node can close.

View File

@@ -2,7 +2,6 @@ package rpc
import (
"io/ioutil"
"os"
"testing"
"github.com/sirupsen/logrus"
@@ -12,5 +11,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
os.Exit(m.Run())
m.Run()
}

View File

@@ -5,7 +5,6 @@ import (
"crypto/rand"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
@@ -23,7 +22,7 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
os.Exit(m.Run())
m.Run()
}
func TestBootnode_OK(t *testing.T) {

View File

@@ -5,7 +5,6 @@ import (
"encoding/binary"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
@@ -26,7 +25,7 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
os.Exit(m.Run())
m.Run()
}
func sendDeposits(t *testing.T, testAcc *contracts.TestAccount,

View File

@@ -23,10 +23,7 @@ func TestMain(m *testing.M) {
}
}
defer cleanup()
code := m.Run()
// os.Exit will prevent defer from being called
cleanup()
os.Exit(code)
m.Run()
}
func TestStop_CancelsContext(t *testing.T) {