diff --git a/beacon-chain/cache/BUILD.bazel b/beacon-chain/cache/BUILD.bazel index a7e9b8e1b9..9704a627fc 100644 --- a/beacon-chain/cache/BUILD.bazel +++ b/beacon-chain/cache/BUILD.bazel @@ -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", diff --git a/beacon-chain/cache/feature_flag_test.go b/beacon-chain/cache/cache_test.go similarity index 70% rename from beacon-chain/cache/feature_flag_test.go rename to beacon-chain/cache/cache_test.go index efc2cfcec4..5f6d3a68ac 100644 --- a/beacon-chain/cache/feature_flag_test.go +++ b/beacon-chain/cache/cache_test.go @@ -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() } diff --git a/beacon-chain/core/epoch/spectest/spectest_test.go b/beacon-chain/core/epoch/spectest/spectest_test.go index f0bec495b8..4071490256 100644 --- a/beacon-chain/core/epoch/spectest/spectest_test.go +++ b/beacon-chain/core/epoch/spectest/spectest_test.go @@ -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() } diff --git a/beacon-chain/p2p/peers/peers_test.go b/beacon-chain/p2p/peers/peers_test.go index c0746c59af..c168ee8ad4 100644 --- a/beacon-chain/p2p/peers/peers_test.go +++ b/beacon-chain/p2p/peers/peers_test.go @@ -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() } diff --git a/beacon-chain/p2p/peers/scorers/scorers_test.go b/beacon-chain/p2p/peers/scorers/scorers_test.go index 53935bd7af..4596e2594b 100644 --- a/beacon-chain/p2p/peers/scorers/scorers_test.go +++ b/beacon-chain/p2p/peers/scorers/scorers_test.go @@ -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. diff --git a/beacon-chain/powchain/powchain_test.go b/beacon-chain/powchain/powchain_test.go index 7c09a46d6c..f7a1c5aa3b 100644 --- a/beacon-chain/powchain/powchain_test.go +++ b/beacon-chain/powchain/powchain_test.go @@ -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() } diff --git a/beacon-chain/rpc/beacon/beacon_test.go b/beacon-chain/rpc/beacon/beacon_test.go index 56d5a873e6..3ff6e95ffb 100644 --- a/beacon-chain/rpc/beacon/beacon_test.go +++ b/beacon-chain/rpc/beacon/beacon_test.go @@ -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() } diff --git a/beacon-chain/rpc/validator/validator_test.go b/beacon-chain/rpc/validator/validator_test.go index 1236dd7b0a..e7e93219a9 100644 --- a/beacon-chain/rpc/validator/validator_test.go +++ b/beacon-chain/rpc/validator/validator_test.go @@ -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() } diff --git a/beacon-chain/state/stateutil/stateutil_test.go b/beacon-chain/state/stateutil/stateutil_test.go index b78c7b27df..9f8d2aa768 100644 --- a/beacon-chain/state/stateutil/stateutil_test.go +++ b/beacon-chain/state/stateutil/stateutil_test.go @@ -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() } diff --git a/beacon-chain/sync/initial-sync/initial_sync_test.go b/beacon-chain/sync/initial-sync/initial_sync_test.go index 1c432314f8..aa99dd7661 100644 --- a/beacon-chain/sync/initial-sync/initial_sync_test.go +++ b/beacon-chain/sync/initial-sync/initial_sync_test.go @@ -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) { diff --git a/beacon-chain/sync/sync_test.go b/beacon-chain/sync/sync_test.go index 662ad0f12e..6d8afea10c 100644 --- a/beacon-chain/sync/sync_test.go +++ b/beacon-chain/sync/sync_test.go @@ -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() } diff --git a/shared/aggregation/attestations/attestations_test.go b/shared/aggregation/attestations/attestations_test.go index b2bd904ea5..7239543fea 100644 --- a/shared/aggregation/attestations/attestations_test.go +++ b/shared/aggregation/attestations/attestations_test.go @@ -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) { diff --git a/shared/slotutil/slotutil_test.go b/shared/slotutil/slotutil_test.go index f3c432ce65..4d41353ad6 100644 --- a/shared/slotutil/slotutil_test.go +++ b/shared/slotutil/slotutil_test.go @@ -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() } diff --git a/slasher/beaconclient/service_test.go b/slasher/beaconclient/service_test.go index 8dd801c112..4ccec6b1ad 100644 --- a/slasher/beaconclient/service_test.go +++ b/slasher/beaconclient/service_test.go @@ -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() } diff --git a/slasher/db/kv/kv_test.go b/slasher/db/kv/kv_test.go index f9c93ddbba..e74ce52b2a 100644 --- a/slasher/db/kv/kv_test.go +++ b/slasher/db/kv/kv_test.go @@ -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 { diff --git a/slasher/detection/attestations/attestations_test.go b/slasher/detection/attestations/attestations_test.go index 3b14cda82d..5c376fcc3f 100644 --- a/slasher/detection/attestations/attestations_test.go +++ b/slasher/detection/attestations/attestations_test.go @@ -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() } diff --git a/slasher/detection/proposals/proposals_test.go b/slasher/detection/proposals/proposals_test.go index 5a72fb8983..1cd778d3fa 100644 --- a/slasher/detection/proposals/proposals_test.go +++ b/slasher/detection/proposals/proposals_test.go @@ -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() } diff --git a/slasher/node/node_test.go b/slasher/node/node_test.go index ac00f66243..6ee40fb151 100644 --- a/slasher/node/node_test.go +++ b/slasher/node/node_test.go @@ -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. diff --git a/slasher/rpc/rpc_test.go b/slasher/rpc/rpc_test.go index 6d99b8fa64..84cb6ac67e 100644 --- a/slasher/rpc/rpc_test.go +++ b/slasher/rpc/rpc_test.go @@ -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() } diff --git a/tools/bootnode/bootnode_test.go b/tools/bootnode/bootnode_test.go index 99ee6253d3..d5f624c297 100644 --- a/tools/bootnode/bootnode_test.go +++ b/tools/bootnode/bootnode_test.go @@ -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) { diff --git a/tools/sendDepositTx/sendDeposits_test.go b/tools/sendDepositTx/sendDeposits_test.go index c2b00e47a4..7a364f858a 100644 --- a/tools/sendDepositTx/sendDeposits_test.go +++ b/tools/sendDepositTx/sendDeposits_test.go @@ -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, diff --git a/validator/client/service_test.go b/validator/client/service_test.go index df5ce6c170..1a9c156e2b 100644 --- a/validator/client/service_test.go +++ b/validator/client/service_test.go @@ -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) {