mirror of
https://github.com/status-im/status-go.git
synced 2025-01-21 20:20:29 +00:00
Issue/fix dataraces in jail tests#457 (#460)
This commit is contained in:
parent
0a82e67379
commit
6bf980a1a7
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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{})
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user