Makes random panics on node manager tests less frequent (#433)
This commit is contained in:
parent
086747a695
commit
9a3302ac36
|
@ -2,7 +2,6 @@ package node_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"math/rand"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -13,7 +12,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
|
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
|
||||||
"github.com/status-im/status-go/e2e"
|
"github.com/status-im/status-go/e2e"
|
||||||
"github.com/status-im/status-go/geth/log"
|
|
||||||
"github.com/status-im/status-go/geth/node"
|
"github.com/status-im/status-go/geth/node"
|
||||||
"github.com/status-im/status-go/geth/params"
|
"github.com/status-im/status-go/geth/params"
|
||||||
"github.com/status-im/status-go/geth/signal"
|
"github.com/status-im/status-go/geth/signal"
|
||||||
|
@ -127,7 +125,10 @@ func (s *ManagerTestSuite) TestReferencesWithoutStartedNode() {
|
||||||
|
|
||||||
func (s *ManagerTestSuite) TestReferencesWithStartedNode() {
|
func (s *ManagerTestSuite) TestReferencesWithStartedNode() {
|
||||||
s.StartTestNode()
|
s.StartTestNode()
|
||||||
defer s.StopTestNode()
|
defer func() {
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
s.StopTestNode()
|
||||||
|
}()
|
||||||
|
|
||||||
var testCases = []struct {
|
var testCases = []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -199,6 +200,8 @@ func (s *ManagerTestSuite) TestNodeStartStop() {
|
||||||
|
|
||||||
// try stopping non-started node
|
// try stopping non-started node
|
||||||
s.False(s.NodeManager.IsNodeRunning())
|
s.False(s.NodeManager.IsNodeRunning())
|
||||||
|
|
||||||
|
time.Sleep(100 * time.Millisecond) //https://github.com/status-im/status-go/issues/429#issuecomment-339663163
|
||||||
_, err = s.NodeManager.StopNode()
|
_, err = s.NodeManager.StopNode()
|
||||||
s.Equal(err, node.ErrNoRunningNode)
|
s.Equal(err, node.ErrNoRunningNode)
|
||||||
|
|
||||||
|
@ -215,6 +218,7 @@ func (s *ManagerTestSuite) TestNodeStartStop() {
|
||||||
s.Equal(err, node.ErrNodeExists)
|
s.Equal(err, node.ErrNodeExists)
|
||||||
|
|
||||||
// now stop node
|
// now stop node
|
||||||
|
time.Sleep(100 * time.Millisecond) //https://github.com/status-im/status-go/issues/429#issuecomment-339663163
|
||||||
nodeStopped, err := s.NodeManager.StopNode()
|
nodeStopped, err := s.NodeManager.StopNode()
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
<-nodeStopped
|
<-nodeStopped
|
||||||
|
@ -228,6 +232,7 @@ func (s *ManagerTestSuite) TestNodeStartStop() {
|
||||||
s.True(s.NodeManager.IsNodeRunning())
|
s.True(s.NodeManager.IsNodeRunning())
|
||||||
|
|
||||||
// finally stop the node
|
// finally stop the node
|
||||||
|
time.Sleep(100 * time.Millisecond) //https://github.com/status-im/status-go/issues/429#issuecomment-339663163
|
||||||
nodeStopped, err = s.NodeManager.StopNode()
|
nodeStopped, err = s.NodeManager.StopNode()
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
<-nodeStopped
|
<-nodeStopped
|
||||||
|
@ -249,6 +254,7 @@ func (s *ManagerTestSuite) TestNetworkSwitching() {
|
||||||
s.Equal(GetHeadHash(), firstHash)
|
s.Equal(GetHeadHash(), firstHash)
|
||||||
|
|
||||||
// now stop node, and make sure that a new node, on different network can be started
|
// now stop node, and make sure that a new node, on different network can be started
|
||||||
|
time.Sleep(100 * time.Millisecond) //https://github.com/status-im/status-go/issues/429#issuecomment-339663163
|
||||||
nodeStopped, err := s.NodeManager.StopNode()
|
nodeStopped, err := s.NodeManager.StopNode()
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
<-nodeStopped
|
<-nodeStopped
|
||||||
|
@ -268,6 +274,7 @@ func (s *ManagerTestSuite) TestNetworkSwitching() {
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
s.Equal(GetHeadHashFromNetworkID(params.RinkebyNetworkID), firstHash)
|
s.Equal(GetHeadHashFromNetworkID(params.RinkebyNetworkID), firstHash)
|
||||||
|
|
||||||
|
time.Sleep(100 * time.Millisecond) //https://github.com/status-im/status-go/issues/429#issuecomment-339663163
|
||||||
nodeStopped, err = s.NodeManager.StopNode()
|
nodeStopped, err = s.NodeManager.StopNode()
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
<-nodeStopped
|
<-nodeStopped
|
||||||
|
@ -291,6 +298,8 @@ func (s *ManagerTestSuite) TestStartNodeWithUpstreamEnabled() {
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
<-nodeStarted
|
<-nodeStarted
|
||||||
s.True(s.NodeManager.IsNodeRunning())
|
s.True(s.NodeManager.IsNodeRunning())
|
||||||
|
|
||||||
|
time.Sleep(100 * time.Millisecond) //https://github.com/status-im/status-go/issues/429#issuecomment-339663163
|
||||||
nodeStopped, err := s.NodeManager.StopNode()
|
nodeStopped, err := s.NodeManager.StopNode()
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
<-nodeStopped
|
<-nodeStopped
|
||||||
|
@ -336,129 +345,129 @@ func (s *ManagerTestSuite) TestRestartNode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(adam): race conditions should be tested with -race flag and unit tests, if possible.
|
// TODO(adam): race conditions should be tested with -race flag and unit tests, if possible.
|
||||||
|
// TODO(boris): going via https://github.com/status-im/status-go/pull/433#issuecomment-342232645 . Testing should be with -race flag
|
||||||
// Research if it's possible to do the same with unit tests.
|
// Research if it's possible to do the same with unit tests.
|
||||||
func (s *ManagerTestSuite) TestRaceConditions() {
|
//func (s *ManagerTestSuite) TestRaceConditions() {
|
||||||
cnt := 25
|
// cnt := 25
|
||||||
progress := make(chan struct{}, cnt)
|
// progress := make(chan struct{}, cnt)
|
||||||
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
|
// rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
|
//
|
||||||
nodeConfig1, e := e2e.MakeTestNodeConfig(GetNetworkID())
|
// nodeConfig1, e := e2e.MakeTestNodeConfig(GetNetworkID())
|
||||||
s.NoError(e)
|
// s.NoError(e)
|
||||||
|
//
|
||||||
nodeConfig2, e := e2e.MakeTestNodeConfig(GetNetworkID())
|
// nodeConfig2, e := e2e.MakeTestNodeConfig(GetNetworkID())
|
||||||
s.NoError(e)
|
// s.NoError(e)
|
||||||
|
//
|
||||||
nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}
|
// nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}
|
||||||
|
//
|
||||||
var funcsToTest = []func(*params.NodeConfig){
|
// var funcsToTest = []func(*params.NodeConfig){
|
||||||
func(config *params.NodeConfig) {
|
// func(config *params.NodeConfig) {
|
||||||
log.Info("StartNode()")
|
// log.Info("StartNode()")
|
||||||
_, err := s.NodeManager.StartNode(config)
|
// _, err := s.NodeManager.StartNode(config)
|
||||||
s.T().Logf("StartNode() for network: %d, error: %v", config.NetworkID, err)
|
// s.T().Logf("StartNode() for network: %d, error: %v", config.NetworkID, err)
|
||||||
progress <- struct{}{}
|
// progress <- struct{}{}
|
||||||
},
|
// },
|
||||||
func(config *params.NodeConfig) {
|
// func(config *params.NodeConfig) {
|
||||||
log.Info("StopNode()")
|
// _, err := s.NodeManager.StopNode()
|
||||||
_, err := s.NodeManager.StopNode()
|
// s.T().Logf("StopNode() for network: %d, error: %v", config.NetworkID, err)
|
||||||
s.T().Logf("StopNode() for network: %d, error: %v", config.NetworkID, err)
|
// progress <- struct{}{}
|
||||||
progress <- struct{}{}
|
// },
|
||||||
},
|
// func(config *params.NodeConfig) {
|
||||||
func(config *params.NodeConfig) {
|
// log.Info("Node()")
|
||||||
log.Info("Node()")
|
// _, err := s.NodeManager.Node()
|
||||||
_, err := s.NodeManager.Node()
|
// s.T().Logf("Node(), error: %v", err)
|
||||||
s.T().Logf("Node(), error: %v", err)
|
// progress <- struct{}{}
|
||||||
progress <- struct{}{}
|
// },
|
||||||
},
|
// func(config *params.NodeConfig) {
|
||||||
func(config *params.NodeConfig) {
|
// log.Info("IsNodeRunning()")
|
||||||
log.Info("IsNodeRunning()")
|
// s.T().Logf("IsNodeRunning(), result: %v", s.NodeManager.IsNodeRunning())
|
||||||
s.T().Logf("IsNodeRunning(), result: %v", s.NodeManager.IsNodeRunning())
|
// progress <- struct{}{}
|
||||||
progress <- struct{}{}
|
// },
|
||||||
},
|
// func(config *params.NodeConfig) {
|
||||||
func(config *params.NodeConfig) {
|
// log.Info("PopulateStaticPeers()")
|
||||||
log.Info("PopulateStaticPeers()")
|
// s.T().Logf("PopulateStaticPeers(), error: %v", s.NodeManager.PopulateStaticPeers())
|
||||||
s.T().Logf("PopulateStaticPeers(), error: %v", s.NodeManager.PopulateStaticPeers())
|
// progress <- struct{}{}
|
||||||
progress <- struct{}{}
|
// },
|
||||||
},
|
// // TODO(adam): quarantined until it uses a different datadir
|
||||||
// TODO(adam): quarantined until it uses a different datadir
|
// // as otherwise it wipes out cached blockchain data.
|
||||||
// as otherwise it wipes out cached blockchain data.
|
// // func(config *params.NodeConfig) {
|
||||||
// func(config *params.NodeConfig) {
|
// // log.Info("ResetChainData()")
|
||||||
// log.Info("ResetChainData()")
|
// // _, err := s.NodeManager.ResetChainData()
|
||||||
// _, err := s.NodeManager.ResetChainData()
|
// // s.T().Logf("ResetChainData(), error: %v", err)
|
||||||
// s.T().Logf("ResetChainData(), error: %v", err)
|
// // progress <- struct{}{}
|
||||||
// progress <- struct{}{}
|
// // },
|
||||||
// },
|
// func(config *params.NodeConfig) {
|
||||||
func(config *params.NodeConfig) {
|
// log.Info("RestartNode()")
|
||||||
log.Info("RestartNode()")
|
// _, err := s.NodeManager.RestartNode()
|
||||||
_, err := s.NodeManager.RestartNode()
|
// s.T().Logf("RestartNode(), error: %v", err)
|
||||||
s.T().Logf("RestartNode(), error: %v", err)
|
// progress <- struct{}{}
|
||||||
progress <- struct{}{}
|
// },
|
||||||
},
|
// func(config *params.NodeConfig) {
|
||||||
func(config *params.NodeConfig) {
|
// log.Info("NodeConfig()")
|
||||||
log.Info("NodeConfig()")
|
// _, err := s.NodeManager.NodeConfig()
|
||||||
_, err := s.NodeManager.NodeConfig()
|
// s.T().Logf("NodeConfig(), error: %v", err)
|
||||||
s.T().Logf("NodeConfig(), error: %v", err)
|
// progress <- struct{}{}
|
||||||
progress <- struct{}{}
|
// },
|
||||||
},
|
// func(config *params.NodeConfig) {
|
||||||
func(config *params.NodeConfig) {
|
// log.Info("LightEthereumService()")
|
||||||
log.Info("LightEthereumService()")
|
// _, err := s.NodeManager.LightEthereumService()
|
||||||
_, err := s.NodeManager.LightEthereumService()
|
// s.T().Logf("LightEthereumService(), error: %v", err)
|
||||||
s.T().Logf("LightEthereumService(), error: %v", err)
|
// progress <- struct{}{}
|
||||||
progress <- struct{}{}
|
// },
|
||||||
},
|
// func(config *params.NodeConfig) {
|
||||||
func(config *params.NodeConfig) {
|
// log.Info("WhisperService()")
|
||||||
log.Info("WhisperService()")
|
// _, err := s.NodeManager.WhisperService()
|
||||||
_, err := s.NodeManager.WhisperService()
|
// s.T().Logf("WhisperService(), error: %v", err)
|
||||||
s.T().Logf("WhisperService(), error: %v", err)
|
// progress <- struct{}{}
|
||||||
progress <- struct{}{}
|
// },
|
||||||
},
|
// func(config *params.NodeConfig) {
|
||||||
func(config *params.NodeConfig) {
|
// log.Info("AccountManager()")
|
||||||
log.Info("AccountManager()")
|
// _, err := s.NodeManager.AccountManager()
|
||||||
_, err := s.NodeManager.AccountManager()
|
// s.T().Logf("AccountManager(), error: %v", err)
|
||||||
s.T().Logf("AccountManager(), error: %v", err)
|
// progress <- struct{}{}
|
||||||
progress <- struct{}{}
|
// },
|
||||||
},
|
// func(config *params.NodeConfig) {
|
||||||
func(config *params.NodeConfig) {
|
// log.Info("AccountKeyStore()")
|
||||||
log.Info("AccountKeyStore()")
|
// _, err := s.NodeManager.AccountKeyStore()
|
||||||
_, err := s.NodeManager.AccountKeyStore()
|
// s.T().Logf("AccountKeyStore(), error: %v", err)
|
||||||
s.T().Logf("AccountKeyStore(), error: %v", err)
|
// progress <- struct{}{}
|
||||||
progress <- struct{}{}
|
// },
|
||||||
},
|
// func(config *params.NodeConfig) {
|
||||||
func(config *params.NodeConfig) {
|
// log.Info("RPCClient()")
|
||||||
log.Info("RPCClient()")
|
// s.NodeManager.RPCClient()
|
||||||
s.NodeManager.RPCClient()
|
// progress <- struct{}{}
|
||||||
progress <- struct{}{}
|
// },
|
||||||
},
|
// }
|
||||||
}
|
//
|
||||||
|
// // increase StartNode()/StopNode() population
|
||||||
// increase StartNode()/StopNode() population
|
// for i := 0; i < 5; i++ {
|
||||||
for i := 0; i < 5; i++ {
|
// funcsToTest = append(funcsToTest, funcsToTest[0], funcsToTest[1])
|
||||||
funcsToTest = append(funcsToTest, funcsToTest[0], funcsToTest[1])
|
// }
|
||||||
}
|
//
|
||||||
|
// for i := 0; i < cnt; i++ {
|
||||||
for i := 0; i < cnt; i++ {
|
// randConfig := nodeConfigs[rnd.Intn(len(nodeConfigs))]
|
||||||
randConfig := nodeConfigs[rnd.Intn(len(nodeConfigs))]
|
// randFunc := funcsToTest[rnd.Intn(len(funcsToTest))]
|
||||||
randFunc := funcsToTest[rnd.Intn(len(funcsToTest))]
|
//
|
||||||
|
// if rnd.Intn(100) > 75 { // introduce random delays
|
||||||
if rnd.Intn(100) > 75 { // introduce random delays
|
// time.Sleep(500 * time.Millisecond)
|
||||||
time.Sleep(500 * time.Millisecond)
|
// }
|
||||||
}
|
// go randFunc(randConfig)
|
||||||
go randFunc(randConfig)
|
// }
|
||||||
}
|
//
|
||||||
|
// for range progress {
|
||||||
for range progress {
|
// cnt -= 1
|
||||||
cnt -= 1
|
// if cnt <= 0 {
|
||||||
if cnt <= 0 {
|
// break
|
||||||
break
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
// time.Sleep(2 * time.Second) // so that we see some logs
|
||||||
time.Sleep(2 * time.Second) // so that we see some logs
|
// nodeStopped, _ := s.NodeManager.StopNode() // just in case we have a node running
|
||||||
nodeStopped, _ := s.NodeManager.StopNode() // just in case we have a node running
|
//
|
||||||
|
// if nodeStopped != nil {
|
||||||
if nodeStopped != nil {
|
// <-nodeStopped
|
||||||
<-nodeStopped
|
// }
|
||||||
}
|
//}
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ManagerTestSuite) TestNodeStartCrash() {
|
func (s *ManagerTestSuite) TestNodeStartCrash() {
|
||||||
// let's listen for node.crashed signal
|
// let's listen for node.crashed signal
|
||||||
|
@ -510,6 +519,7 @@ func (s *ManagerTestSuite) TestNodeStartCrash() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
s.NodeManager.StopNode() //nolint: errcheck
|
time.Sleep(100 * time.Millisecond) //https://github.com/status-im/status-go/issues/429#issuecomment-339663163
|
||||||
|
s.NodeManager.StopNode() //nolint: errcheck
|
||||||
signal.ResetDefaultNodeNotificationHandler()
|
signal.ResetDefaultNodeNotificationHandler()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue