node manager: fixes race when logging node stopping status

This commit is contained in:
Victor Farazdagi 2017-05-25 14:23:01 +03:00
parent f31b12ad56
commit 3c961473e1
2 changed files with 63 additions and 5 deletions

58
geth/api/api_test.go Normal file
View File

@ -0,0 +1,58 @@
package api_test
import (
"testing"
"github.com/status-im/status-go/geth/api"
"github.com/status-im/status-go/geth/params"
. "github.com/status-im/status-go/geth/testing"
"github.com/stretchr/testify/suite"
)
func TestAPI(t *testing.T) {
suite.Run(t, new(APITestSuite))
}
type APITestSuite struct {
suite.Suite
api *api.StatusAPI
}
func (s *APITestSuite) SetupTest() {
require := s.Require()
statusAPI := api.NewStatusAPI()
require.NotNil(statusAPI)
require.IsType(&api.StatusAPI{}, statusAPI)
s.api = statusAPI
}
func (s *APITestSuite) TestStartStopRaces() {
require := s.Require()
nodeConfig, err := MakeTestNodeConfig(params.RinkebyNetworkID)
require.NoError(err)
progress := make(chan struct{}, 100)
start := func() {
s.api.StartNode(nodeConfig)
progress <- struct{}{}
}
stop := func() {
s.api.StopNode()
progress <- struct{}{}
}
for i := 0; i < 50; i++ {
go start()
go stop()
}
cnt := 0
for range progress {
cnt += 1
if cnt >= 100 {
break
}
}
}

View File

@ -14,7 +14,6 @@ import (
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/rpc"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
@ -138,10 +137,11 @@ func (m *NodeManager) onNodeStarted(nodeStarted chan struct{}) {
}
// obtain node info
var nodeInfo *p2p.NodeInfo
enode := "none"
if server := m.node.Server(); server != nil {
if nodeInfo = server.NodeInfo(); nodeInfo != nil {
log.Info("Node is ready", "enode", nodeInfo.Enode)
if nodeInfo := server.NodeInfo(); nodeInfo != nil {
enode = nodeInfo.Enode
log.Info("Node is ready", "enode", enode)
}
}
@ -159,7 +159,7 @@ func (m *NodeManager) onNodeStarted(nodeStarted chan struct{}) {
Event: struct{}{},
})
close(m.nodeStopped)
log.Info("Node is stopped", "enode", nodeInfo.Enode)
log.Info("Node is stopped", "enode", enode)
}
// IsNodeRunning confirm that node is running