Issue/fix dataraces in jail tests#457 (#460)

This commit is contained in:
b00ris 2017-11-28 00:56:52 +03:00 committed by Adam Babik
parent 0a82e67379
commit 6bf980a1a7
3 changed files with 12 additions and 9 deletions

View File

@ -123,8 +123,8 @@ func (s *JailRPCTestSuite) TestContractDeployment() {
var txHash gethcommon.Hash
signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) {
var envelope signal.Envelope
err = json.Unmarshal([]byte(jsonEvent), &envelope)
s.NoError(err, "cannot unmarshal JSON: %s", jsonEvent)
unmarshalErr := json.Unmarshal([]byte(jsonEvent), &envelope)
s.NoError(unmarshalErr, "cannot unmarshal JSON: %s", jsonEvent)
if envelope.Type == txqueue.EventTransactionQueued {
event := envelope.Event.(map[string]interface{})
@ -133,8 +133,9 @@ func (s *JailRPCTestSuite) TestContractDeployment() {
s.NoError(s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password))
txID := event["id"].(string)
txHash, err = s.Backend.CompleteTransaction(common.QueuedTxID(txID), TestConfig.Account1.Password)
if s.NoError(err, event["id"]) {
var txErr error
txHash, txErr = s.Backend.CompleteTransaction(common.QueuedTxID(txID), TestConfig.Account1.Password)
if s.NoError(txErr, event["id"]) {
s.T().Logf("contract transaction complete, URL: %s", "https://ropsten.etherscan.io/tx/"+txHash.Hex())
}

View File

@ -146,10 +146,11 @@ func (s *JailTestSuite) TestEventSignal() {
opCompletedSuccessfully := make(chan struct{}, 1)
// replace transaction notification handler
defer signal.ResetDefaultNodeNotificationHandler()
signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) {
var envelope signal.Envelope
err = json.Unmarshal([]byte(jsonEvent), &envelope)
s.NoError(err)
unmarshalErr := json.Unmarshal([]byte(jsonEvent), &envelope)
s.NoError(unmarshalErr)
if envelope.Type == jail.EventSignal {
event := envelope.Event.(map[string]interface{})

View File

@ -14,6 +14,7 @@ import (
"github.com/status-im/status-go/geth/rpc"
"github.com/status-im/status-go/geth/signal"
"github.com/stretchr/testify/suite"
"sync/atomic"
)
func TestHandlersTestSuite(t *testing.T) {
@ -24,14 +25,14 @@ type HandlersTestSuite struct {
suite.Suite
responseFixture string
ts *httptest.Server
tsCalls int
tsCalls int32
client *gethrpc.Client
}
func (s *HandlersTestSuite) SetupTest() {
s.responseFixture = `{"json-rpc":"2.0","id":10,"result":true}`
s.ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
s.tsCalls++
atomic.AddInt32(&s.tsCalls, 1)
fmt.Fprintln(w, s.responseFixture)
}))
@ -112,7 +113,7 @@ func (s *HandlersTestSuite) TestWeb3SendAsyncHandlerWithoutCallbackSuccess() {
// As there is no callback, it's not possible to detect when
// the request hit the server.
time.Sleep(time.Millisecond * 100)
s.Equal(1, s.tsCalls)
s.Equal(int32(1), atomic.LoadInt32(&s.tsCalls))
}
func (s *HandlersTestSuite) TestWeb3SendAsyncHandlerFailure() {