mirror of
https://github.com/status-im/status-go.git
synced 2025-01-24 13:41:24 +00:00
281b304edb
This change moves our e2e tests into a separate package to make room for proper unit and integration tests. This is Phase 1 described in #371. Changes: Makefile has separate directives to run unit/integration tests and e2e tests, CI runs unit/integration tests first and then e2e tests, E2e tests are in reliability order, i.e. the least reliable tests are run in the end to be sure that nothing else is broken, Some tests are fixed or quarantined.
121 lines
3.0 KiB
Go
121 lines
3.0 KiB
Go
package api_test
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"math/rand"
|
|
"os"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/status-im/status-go/e2e"
|
|
"github.com/status-im/status-go/geth/api"
|
|
"github.com/status-im/status-go/geth/log"
|
|
"github.com/status-im/status-go/geth/params"
|
|
"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() {
|
|
s.api = api.NewStatusAPI()
|
|
s.NotNil(s.api)
|
|
}
|
|
|
|
func (s *APITestSuite) TestCHTUpdate() {
|
|
tmpDir, err := ioutil.TempDir(os.TempDir(), "cht-updates")
|
|
s.NoError(err)
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
configJSON := `{
|
|
"NetworkId": ` + strconv.Itoa(params.RopstenNetworkID) + `,
|
|
"DataDir": "` + tmpDir + `",
|
|
"LogLevel": "INFO",
|
|
"RPCEnabled": true
|
|
}`
|
|
//nodeConfig, err := params.LoadNodeConfig(configJSON)
|
|
_, err = params.LoadNodeConfig(configJSON)
|
|
s.NoError(err)
|
|
|
|
// start node
|
|
//nodeConfig.DevMode = true
|
|
//s.api.StartNode(nodeConfig)
|
|
//s.api.StopNode()
|
|
// TODO(tiabc): Test that CHT is really updated.
|
|
}
|
|
|
|
func (s *APITestSuite) TestRaceConditions() {
|
|
cnt := 25
|
|
progress := make(chan struct{}, cnt)
|
|
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
nodeConfig1, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
|
|
s.NoError(err)
|
|
|
|
nodeConfig2, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
|
|
s.NoError(err)
|
|
|
|
nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}
|
|
|
|
var funcsToTest = []func(*params.NodeConfig){
|
|
func(config *params.NodeConfig) {
|
|
log.Info("StartNodeAsync()")
|
|
_, err := s.api.StartNodeAsync(config)
|
|
s.T().Logf("StartNodeAsync() for network: %d, error: %v", config.NetworkID, err)
|
|
progress <- struct{}{}
|
|
},
|
|
func(config *params.NodeConfig) {
|
|
log.Info("StopNodeAsync()")
|
|
_, err := s.api.StopNodeAsync()
|
|
s.T().Logf("StopNodeAsync(), error: %v", err)
|
|
progress <- struct{}{}
|
|
},
|
|
func(config *params.NodeConfig) {
|
|
log.Info("RestartNodeAsync()")
|
|
_, err := s.api.RestartNodeAsync()
|
|
s.T().Logf("RestartNodeAsync(), error: %v", err)
|
|
progress <- struct{}{}
|
|
},
|
|
// TODO(adam): quarantined until it uses a different datadir
|
|
// as otherwise it wipes out cached blockchain data.
|
|
// func(config *params.NodeConfig) {
|
|
// log.Info("ResetChainDataAsync()")
|
|
// _, err := s.api.ResetChainDataAsync()
|
|
// s.T().Logf("ResetChainDataAsync(), error: %v", err)
|
|
// progress <- struct{}{}
|
|
// },
|
|
}
|
|
|
|
// increase StartNode()/StopNode() population
|
|
for i := 0; i < 5; i++ {
|
|
funcsToTest = append(funcsToTest, funcsToTest[0], funcsToTest[1])
|
|
}
|
|
|
|
for i := 0; i < cnt; i++ {
|
|
randConfig := nodeConfigs[rnd.Intn(len(nodeConfigs))]
|
|
randFunc := funcsToTest[rnd.Intn(len(funcsToTest))]
|
|
|
|
if rnd.Intn(100) > 75 { // introduce random delays
|
|
time.Sleep(500 * time.Millisecond)
|
|
}
|
|
go randFunc(randConfig)
|
|
}
|
|
|
|
for range progress {
|
|
cnt -= 1
|
|
if cnt <= 0 {
|
|
break
|
|
}
|
|
}
|
|
|
|
time.Sleep(2 * time.Second) // so that we see some logs
|
|
s.api.StopNode() // just in case we have a node running
|
|
}
|