Skip to content

Commit

Permalink
Remove redundant calls to os.exit() in TestMain (#7761)
Browse files Browse the repository at this point in the history
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
farazdagi and prylabs-bulldozer[bot] committed Nov 10, 2020
1 parent 7b0ee3a commit 09e3f03
Show file tree
Hide file tree
Showing 22 changed files with 35 additions and 74 deletions.
2 changes: 1 addition & 1 deletion beacon-chain/cache/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cache

import (
"os"
"testing"

"github.com/prysmaticlabs/prysm/shared/featureconfig"
Expand All @@ -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()
}
6 changes: 2 additions & 4 deletions beacon-chain/core/epoch/spectest/spectest_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package spectest

import (
"os"
"testing"

"github.com/prysmaticlabs/prysm/shared/params"
)

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()
}
7 changes: 1 addition & 6 deletions beacon-chain/p2p/peers/peers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package peers_test

import (
"io/ioutil"
"os"
"testing"

"github.com/prysmaticlabs/prysm/beacon-chain/flags"
Expand All @@ -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()
}
7 changes: 1 addition & 6 deletions beacon-chain/p2p/peers/scorers/scorers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package scorers_test
import (
"io/ioutil"
"math"
"os"
"testing"

"github.com/prysmaticlabs/prysm/beacon-chain/flags"
Expand All @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/powchain/powchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package powchain

import (
"io/ioutil"
"os"
"testing"

"github.com/sirupsen/logrus"
Expand All @@ -12,5 +11,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

os.Exit(m.Run())
m.Run()
}
13 changes: 7 additions & 6 deletions beacon-chain/rpc/beacon/beacon_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package beacon

import (
"os"
"testing"

"github.com/prysmaticlabs/prysm/beacon-chain/flags"
Expand All @@ -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()
}
8 changes: 2 additions & 6 deletions beacon-chain/rpc/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package validator

import (
"io/ioutil"
"os"
"testing"

"github.com/prysmaticlabs/prysm/shared/params"
Expand All @@ -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()
}
6 changes: 1 addition & 5 deletions beacon-chain/state/stateutil/stateutil_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package stateutil_test

import (
"os"
"testing"

"github.com/prysmaticlabs/prysm/shared/featureconfig"
Expand All @@ -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()
}
8 changes: 2 additions & 6 deletions beacon-chain/sync/initial-sync/initial_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io/ioutil"
"os"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions beacon-chain/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sync

import (
"io/ioutil"
"os"
"testing"

"github.com/prysmaticlabs/prysm/beacon-chain/flags"
Expand All @@ -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()
}
6 changes: 1 addition & 5 deletions shared/aggregation/attestations/attestations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package attestations
import (
"fmt"
"io/ioutil"
"os"
"sort"
"testing"

Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions shared/slotutil/slotutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package slotutil

import (
"io/ioutil"
"os"
"testing"

"github.com/sirupsen/logrus"
Expand All @@ -12,5 +11,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

os.Exit(m.Run())
m.Run()
}
3 changes: 1 addition & 2 deletions slasher/beaconclient/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package beaconclient

import (
"io/ioutil"
"os"
"testing"

"github.com/sirupsen/logrus"
Expand All @@ -17,5 +16,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

os.Exit(m.Run())
m.Run()
}
2 changes: 1 addition & 1 deletion slasher/db/kv/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions slasher/detection/attestations/attestations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package attestations

import (
"io/ioutil"
"os"
"testing"

"github.com/sirupsen/logrus"
Expand All @@ -12,5 +11,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

os.Exit(m.Run())
m.Run()
}
3 changes: 1 addition & 2 deletions slasher/detection/proposals/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package proposals

import (
"io/ioutil"
"os"
"testing"

"github.com/sirupsen/logrus"
Expand All @@ -12,5 +11,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

os.Exit(m.Run())
m.Run()
}
2 changes: 1 addition & 1 deletion slasher/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions slasher/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rpc

import (
"io/ioutil"
"os"
"testing"

"github.com/sirupsen/logrus"
Expand All @@ -12,5 +11,5 @@ func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

os.Exit(m.Run())
m.Run()
}
3 changes: 1 addition & 2 deletions tools/bootnode/bootnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/rand"
"fmt"
"io/ioutil"
"os"
"testing"
"time"

Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions tools/sendDepositTx/sendDeposits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/binary"
"fmt"
"io/ioutil"
"os"
"testing"
"time"

Expand All @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions validator/client/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 09e3f03

Please sign in to comment.