2017-05-25 11:23:01 +00:00
|
|
|
package api_test
|
|
|
|
|
|
|
|
import (
|
2017-05-25 12:34:13 +00:00
|
|
|
"fmt"
|
2017-05-25 11:23:01 +00:00
|
|
|
"testing"
|
2017-05-25 12:34:13 +00:00
|
|
|
"time"
|
2017-05-25 11:23:01 +00:00
|
|
|
|
|
|
|
"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() {
|
2017-05-25 12:34:13 +00:00
|
|
|
fmt.Println("start node")
|
2017-05-25 11:23:01 +00:00
|
|
|
s.api.StartNode(nodeConfig)
|
|
|
|
progress <- struct{}{}
|
|
|
|
}
|
|
|
|
stop := func() {
|
2017-05-25 12:34:13 +00:00
|
|
|
fmt.Println("stop node")
|
2017-05-25 11:23:01 +00:00
|
|
|
s.api.StopNode()
|
|
|
|
progress <- struct{}{}
|
|
|
|
}
|
|
|
|
|
2017-05-25 12:34:13 +00:00
|
|
|
// start one node and sync it a bit
|
|
|
|
start()
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
|
|
|
|
for i := 0; i < 20; i++ {
|
2017-05-25 11:23:01 +00:00
|
|
|
go start()
|
|
|
|
go stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
cnt := 0
|
|
|
|
for range progress {
|
|
|
|
cnt += 1
|
2017-05-25 12:34:13 +00:00
|
|
|
if cnt >= 40 {
|
2017-05-25 11:23:01 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|