From 8cdf76d7fd291ae01263544575dd5052f4e65465 Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@erisindustries.com> Date: Sat, 27 Aug 2016 16:15:56 +0100 Subject: [PATCH] Fix remaining rpc tests, try to sure up integration tests stability --- circle.yml | 4 ++ rpc/tendermint/core/websocket.go | 6 +++ rpc/tendermint/test/client_rpc_test.go | 24 +++--------- rpc/tendermint/test/client_ws_test.go | 3 +- rpc/tendermint/test/common.go | 10 ++++- rpc/tendermint/test/shared.go | 7 +++- rpc/tendermint/test/tests.go | 52 ++++++++++++-------------- 7 files changed, 54 insertions(+), 52 deletions(-) diff --git a/circle.yml b/circle.yml index dc831410..b2bacf46 100644 --- a/circle.yml +++ b/circle.yml @@ -41,7 +41,11 @@ test: - cd $GOPATH_REPO && go install ./cmd/eris-db override: # We only wish to test our packages not vendored ones + - echo "Running unit tests..." - cd $GOPATH_REPO && glide novendor | xargs go test -v + - echo "Running integration tests..." + - cd $GOPATH_REPO && glide novendor | xargs go test -v -tags integration + deployment: master: diff --git a/rpc/tendermint/core/websocket.go b/rpc/tendermint/core/websocket.go index c15ee966..6824b78e 100644 --- a/rpc/tendermint/core/websocket.go +++ b/rpc/tendermint/core/websocket.go @@ -67,3 +67,9 @@ func NewTendermintWebsocketServer(config *server.ServerConfig, listeners: listeners, }, nil } + +func (tmServer *TendermintWebsocketServer) Shutdown() { + for _, listener := range tmServer.listeners { + listener.Close() + } +} diff --git a/rpc/tendermint/test/client_rpc_test.go b/rpc/tendermint/test/client_rpc_test.go index 7cd14afa..1bb84efc 100644 --- a/rpc/tendermint/test/client_rpc_test.go +++ b/rpc/tendermint/test/client_rpc_test.go @@ -18,42 +18,32 @@ func TestHTTPStatus(t *testing.T) { testStatus(t, "HTTP") } -// TODO: test has been disabled and needs to be re-enabled; tracked in issue -// https://github.com/eris-ltd/eris-db/issues/238 -func testHTTPGetAccount(t *testing.T) { +func TestHTTPGetAccount(t *testing.T) { if testing.Short() { t.Skip("skipping test in short mode.") } testGetAccount(t, "HTTP") } -// TODO: test has been disabled and needs to be re-enabled; tracked in issue -// https://github.com/eris-ltd/eris-db/issues/238 -func testHTTPBroadcastTx(t *testing.T) { +func TestHTTPBroadcastTx(t *testing.T) { testBroadcastTx(t, "HTTP") } -// TODO: test has been disabled and needs to be re-enabled; tracked in issue -// https://github.com/eris-ltd/eris-db/issues/238 -func testHTTPGetStorage(t *testing.T) { +func TestHTTPGetStorage(t *testing.T) { if testing.Short() { t.Skip("skipping test in short mode.") } testGetStorage(t, "HTTP") } -// TODO: test has been disabled and needs to be re-enabled; tracked in issue -// https://github.com/eris-ltd/eris-db/issues/238 -func testHTTPCallCode(t *testing.T) { +func TestHTTPCallCode(t *testing.T) { if testing.Short() { t.Skip("skipping test in short mode.") } testCallCode(t, "HTTP") } -// TODO: test has been disabled and needs to be re-enabled; tracked in issue -// https://github.com/eris-ltd/eris-db/issues/238 -func testHTTPCallContract(t *testing.T) { +func TestHTTPCallContract(t *testing.T) { if testing.Short() { t.Skip("skipping test in short mode.") } @@ -99,9 +89,7 @@ func TestJSONCallCode(t *testing.T) { testCallCode(t, "JSONRPC") } -// TODO: test has been disabled and needs to be re-enabled; tracked in issue -// https://github.com/eris-ltd/eris-db/issues/238 -func testJSONCallContract(t *testing.T) { +func TestJSONCallContract(t *testing.T) { if testing.Short() { t.Skip("skipping test in short mode.") } diff --git a/rpc/tendermint/test/client_ws_test.go b/rpc/tendermint/test/client_ws_test.go index dbcc9f5c..76c61fde 100644 --- a/rpc/tendermint/test/client_ws_test.go +++ b/rpc/tendermint/test/client_ws_test.go @@ -218,7 +218,7 @@ func TestWSCallCall(t *testing.T) { receipt = broadcastTx(t, wsTyp, tx) contractAddr2 := receipt.ContractAddr - // susbscribe to the new contracts + // subscribe to the new contracts amt = int64(10001) eid := txs.EventStringAccCall(contractAddr1) subId := subscribeAndGetSubscriptionId(t, wsc, eid) @@ -244,4 +244,3 @@ func TestWSCallCall(t *testing.T) { func TestSubscribe(t *testing.T) { testSubscribe(t) } - diff --git a/rpc/tendermint/test/common.go b/rpc/tendermint/test/common.go index b0d2f07e..81832215 100644 --- a/rpc/tendermint/test/common.go +++ b/rpc/tendermint/test/common.go @@ -2,6 +2,7 @@ package test import ( "github.com/eris-ltd/eris-db/test/fixtures" + rpc_core "github.com/eris-ltd/eris-db/rpc/tendermint/core" "testing" ) @@ -19,7 +20,14 @@ func TestWrapper(runner func() int) int { // start a node ready := make(chan error) - go newNode(ready) + server := make(chan *rpc_core.TendermintWebsocketServer) + defer func(){ + // Shutdown -- make sure we don't hit a race on ffs.RemoveAll + tmServer := <-server + tmServer.Shutdown() + }() + + go newNode(ready, server) err = <-ready if err != nil { diff --git a/rpc/tendermint/test/shared.go b/rpc/tendermint/test/shared.go index 2bcffc1f..d705d278 100644 --- a/rpc/tendermint/test/shared.go +++ b/rpc/tendermint/test/shared.go @@ -9,6 +9,7 @@ import ( "github.com/eris-ltd/eris-db/core" core_types "github.com/eris-ltd/eris-db/core/types" edbcli "github.com/eris-ltd/eris-db/rpc/tendermint/client" + rpc_core "github.com/eris-ltd/eris-db/rpc/tendermint/core" rpc_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" "github.com/eris-ltd/eris-db/server" "github.com/eris-ltd/eris-db/test/fixtures" @@ -102,10 +103,12 @@ func makeUsers(n int) []*acm.PrivAccount { return accounts } -func newNode(ready chan error) { +func newNode(ready chan error, + tmServer chan *rpc_core.TendermintWebsocketServer) { // Run the 'tendermint' rpc server - _, err := testCore.NewGatewayTendermint(config) + server, err := testCore.NewGatewayTendermint(config) ready <- err + tmServer <- server } func saveNewPriv() { diff --git a/rpc/tendermint/test/tests.go b/rpc/tendermint/test/tests.go index 454b6024..c8fac0d6 100644 --- a/rpc/tendermint/test/tests.go +++ b/rpc/tendermint/test/tests.go @@ -91,22 +91,19 @@ func testGetStorage(t *testing.T, typ string) { amt, gasLim, fee := int64(1100), int64(1000), int64(1000) code := []byte{0x60, 0x5, 0x60, 0x1, 0x55} + // Call with nil address will create a contract tx := makeDefaultCallTx(t, typ, nil, code, amt, gasLim, fee) - receipt := broadcastTx(t, typ, tx) - if receipt.CreatesContract == 0 { - t.Fatal("This tx creates a contract") - } - if len(receipt.TxHash) == 0 { - t.Fatal("Failed to compute tx hash") + receipt, err := broadcastTxAndWaitForBlock(t, typ, wsc, tx) + if err != nil { + t.Fatalf("Problem broadcasting transaction: %v", err) } + assert.Equal(t, uint8(1), receipt.CreatesContract, "This transaction should"+ + " create a contract") + assert.NotEqual(t, 0, len(receipt.TxHash), "Receipt should contain a"+ + " transaction hash") contractAddr := receipt.ContractAddr - if len(contractAddr) == 0 { - t.Fatal("Creates contract but resulting address is empty") - } - - // allow it to get mined - waitForEvent(t, wsc, eid, func() {}, doNothing) - mempoolCount = 0 + assert.NotEqual(t, 0, len(contractAddr), "Transactions claims to have"+ + " created a contract but the contract address is empty") v := getStorage(t, typ, contractAddr, []byte{0x1}) got := tm_common.LeftPadWord256(v) @@ -151,22 +148,17 @@ func testCall(t *testing.T, typ string) { amt, gasLim, fee := int64(6969), int64(1000), int64(1000) code, _, _ := simpleContract() tx := makeDefaultCallTx(t, typ, nil, code, amt, gasLim, fee) - receipt := broadcastTx(t, typ, tx) - - if receipt.CreatesContract == 0 { - t.Fatal("This tx creates a contract") - } - if len(receipt.TxHash) == 0 { - t.Fatal("Failed to compute tx hash") + receipt, err := broadcastTxAndWaitForBlock(t, typ, wsc, tx) + if err != nil { + t.Fatalf("Problem broadcasting transaction: %v", err) } + assert.Equal(t, uint8(1), receipt.CreatesContract, "This transaction should"+ + " create a contract") + assert.NotEqual(t, 0, len(receipt.TxHash), "Receipt should contain a"+ + " transaction hash") contractAddr := receipt.ContractAddr - if len(contractAddr) == 0 { - t.Fatal("Creates contract but resulting address is empty") - } - - // allow it to get mined - waitForEvent(t, wsc, eid, func() {}, doNothing) - mempoolCount = 0 + assert.NotEqual(t, 0, len(contractAddr), "Transactions claims to have"+ + " created a contract but the contract address is empty") // run a call through the contract data := []byte{} @@ -226,9 +218,12 @@ func testNameReg(t *testing.T, typ string) { tx.Sign(chainID, user[1]) _, err := broadcastTxAndWaitForBlock(t, typ, wsc, tx) - assert.Error(t, err, "Expected error when updating someone else's unexpired"+ " name registry entry") + + // Wait a couple of blocks to make sure name registration expires + waitNBlocks(t, wsc, 2) + //now the entry should be expired, so we can update as non owner const data2 = "this is not my beautiful house" tx = txs.NewNameTxWithNonce(user[1].PubKey, name, data2, amt, fee, @@ -308,4 +303,3 @@ Subscribe: } } } - -- GitLab