Skip to content

Commit

Permalink
Update TestMain(): do not call os.Exit() explicitly (#8046)
Browse files Browse the repository at this point in the history
* update workspace

* update testmain
  • Loading branch information
farazdagi committed Dec 4, 2020
1 parent ccba8cf commit be078d6
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 205 deletions.
10 changes: 3 additions & 7 deletions beacon-chain/blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

return m.Run()
}
os.Exit(run())
m.Run()
}
10 changes: 3 additions & 7 deletions beacon-chain/cache/cache_test.go
Original file line number Diff line number Diff line change
@@ -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())
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{EnableEth1DataVoteCache: true})
defer resetCfg()
m.Run()
}
16 changes: 6 additions & 10 deletions beacon-chain/core/epoch/spectest/spectest_test.go
Original file line number Diff line number Diff line change
@@ -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)
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()
}
34 changes: 15 additions & 19 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 @@ -11,24 +10,21 @@ import (
)

func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
EnablePeerScorer: true,
})
defer resetCfg()
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
EnablePeerScorer: true,
})
defer resetCfg()

resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
BlockBatchLimit: 64,
BlockBatchLimitBurstFactor: 10,
})
defer func() {
flags.Init(resetFlags)
}()
return m.Run()
}
os.Exit(run())
resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
BlockBatchLimit: 64,
BlockBatchLimitBurstFactor: 10,
})
defer func() {
flags.Init(resetFlags)
}()
m.Run()
}
34 changes: 15 additions & 19 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 @@ -13,26 +12,23 @@ import (
)

func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
EnablePeerScorer: true,
})
defer resetCfg()
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
EnablePeerScorer: true,
})
defer resetCfg()

resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
BlockBatchLimit: 64,
BlockBatchLimitBurstFactor: 10,
})
defer func() {
flags.Init(resetFlags)
}()
return m.Run()
}
os.Exit(run())
resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
BlockBatchLimit: 64,
BlockBatchLimitBurstFactor: 10,
})
defer func() {
flags.Init(resetFlags)
}()
m.Run()
}

// roundScore returns score rounded in accordance with the score manager's rounding factor.
Expand Down
10 changes: 3 additions & 7 deletions beacon-chain/powchain/powchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

return m.Run()
}
os.Exit(run())
m.Run()
}
28 changes: 12 additions & 16 deletions beacon-chain/rpc/beacon/beacon_test.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
package beacon

import (
"os"
"testing"

"github.com/prysmaticlabs/prysm/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/shared/params"
)

func TestMain(m *testing.M) {
run := func() int {
// Use minimal config to reduce test setup time.
prevConfig := params.BeaconConfig().Copy()
defer params.OverrideBeaconConfig(prevConfig)
params.OverrideBeaconConfig(params.MinimalSpecConfig())
// 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)
}()
resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
MinimumSyncPeers: 30,
})
defer func() {
flags.Init(resetFlags)
}()

return m.Run()
}
os.Exit(run())
m.Run()
}
18 changes: 7 additions & 11 deletions beacon-chain/rpc/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ package validator

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

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

func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
// Use minimal config to reduce test setup time.
prevConfig := params.BeaconConfig().Copy()
defer params.OverrideBeaconConfig(prevConfig)
params.OverrideBeaconConfig(params.MinimalSpecConfig())
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
// Use minimal config to reduce test setup time.
prevConfig := params.BeaconConfig().Copy()
defer params.OverrideBeaconConfig(prevConfig)
params.OverrideBeaconConfig(params.MinimalSpecConfig())

return m.Run()
}
os.Exit(run())
m.Run()
}
10 changes: 3 additions & 7 deletions beacon-chain/state/stateutil/stateutil_test.go
Original file line number Diff line number Diff line change
@@ -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())
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{EnableSSZCache: true})
defer resetCfg()
m.Run()
}
38 changes: 17 additions & 21 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 @@ -53,27 +52,24 @@ type peerData struct {
}

func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
EnablePeerScorer: true,
})
defer resetCfg()

resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
BlockBatchLimit: 64,
BlockBatchLimitBurstFactor: 10,
})
defer func() {
flags.Init(resetFlags)
}()
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

return m.Run()
}
os.Exit(run())
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
EnablePeerScorer: true,
})
defer resetCfg()

resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
BlockBatchLimit: 64,
BlockBatchLimitBurstFactor: 10,
})
defer func() {
flags.Init(resetFlags)
}()

m.Run()
}

func initializeTestServices(t *testing.T, blocks []uint64, peers []*peerData) (*mock.ChainService, *p2pt.TestP2P, db.Database) {
Expand Down
26 changes: 11 additions & 15 deletions beacon-chain/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@ package sync

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

"github.com/prysmaticlabs/prysm/beacon-chain/flags"
"github.com/sirupsen/logrus"
)

func TestMain(m *testing.M) {
run := func() int {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)

resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
BlockBatchLimit: 64,
BlockBatchLimitBurstFactor: 10,
})
defer func() {
flags.Init(resetFlags)
}()
return m.Run()
}
os.Exit(run())
resetFlags := flags.Get()
flags.Init(&flags.GlobalFlags{
BlockBatchLimit: 64,
BlockBatchLimitBurstFactor: 10,
})
defer func() {
flags.Init(resetFlags)
}()
m.Run()
}

0 comments on commit be078d6

Please sign in to comment.