Skip to content

Commit

Permalink
Merge PR #6489: Test Network Testing Framework
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Jun 26, 2020
1 parent 3df4dd0 commit 9bf3ff7
Show file tree
Hide file tree
Showing 19 changed files with 883 additions and 115 deletions.
32 changes: 4 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
if: "env.GIT_DIFF != ''"
- name: test & coverage report creation
run: |
cat xaa.txt | xargs go test -mod=readonly -timeout 8m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock'
cat xaa.txt | xargs go test -mod=readonly -timeout 8m -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock'
if: "env.GIT_DIFF != ''"
- name: filter out DONTCOVER
run: |
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
if: "env.GIT_DIFF != ''"
- name: test & coverage report creation
run: |
cat xab.txt | xargs go test -mod=readonly -timeout 6m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock'
cat xab.txt | xargs go test -mod=readonly -timeout 6m -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock'
if: "env.GIT_DIFF != ''"
- name: filter out DONTCOVER
run: |
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
if: "env.GIT_DIFF != ''"
- name: test & coverage report creation
run: |
cat xac.txt | xargs go test -mod=readonly -timeout 6m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock'
cat xac.txt | xargs go test -mod=readonly -timeout 6m -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock'
if: "env.GIT_DIFF != ''"
- name: filter out DONTCOVER
run: |
Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
if: "env.GIT_DIFF != ''"
- name: test & coverage report creation
run: |
cat xad.txt | xargs go test -mod=readonly -timeout 6m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock'
cat xad.txt | xargs go test -mod=readonly -timeout 6m -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock'
if: "env.GIT_DIFF != ''"
- name: filter out DONTCOVER
run: |
Expand Down Expand Up @@ -213,27 +213,3 @@ jobs:
run: |
make test-integration
if: "env.GIT_DIFF != ''"

liveness-test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
id: git_diff
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- name: build image
run: |
make build-docker-local-simapp
- name: start localnet
run: |
make clean build-sim-linux localnet-start
if: "env.GIT_DIFF != ''"
- name: test liveness
run: |
./contrib/localnet_liveness.sh 100 5 50 localhost
if: "env.GIT_DIFF != ''"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposa

### Features

* (tests) [\#6489](https://github.com/cosmos/cosmos-sdk/pull/6489) Introduce package `testutil`, new in-process testing network framework for use in integration and unit tests.
* (crypto/multisig) [\#6241](https://github.com/cosmos/cosmos-sdk/pull/6241) Add Multisig type directly to the repo. Previously this was in tendermint.
* (rest) [\#6167](https://github.com/cosmos/cosmos-sdk/pull/6167) Support `max-body-bytes` CLI flag for the REST service.
* (x/ibc) [\#5588](https://github.com/cosmos/cosmos-sdk/pull/5588) Add [ICS 024 - Host State Machine Requirements](https://github.com/cosmos/ics/tree/master/spec/ics-024-host-requirements) subpackage to `x/ibc` module.
Expand Down
55 changes: 0 additions & 55 deletions contrib/localnet_liveness.sh

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require (
github.com/tendermint/iavl v0.14.0-rc1
github.com/tendermint/tendermint v0.33.5
github.com/tendermint/tm-db v0.5.1
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
google.golang.org/grpc v1.30.0
gopkg.in/yaml.v2 v2.3.0
)
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
5 changes: 2 additions & 3 deletions server/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"net"
"net/http"
"os"
"strings"
"time"

Expand Down Expand Up @@ -33,11 +32,11 @@ type Server struct {
listener net.Listener
}

func New(clientCtx client.Context) *Server {
func New(clientCtx client.Context, logger log.Logger) *Server {
return &Server{
Router: mux.NewRouter(),
ClientCtx: clientCtx,
logger: log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "api-server"),
logger: logger,
}
}

Expand Down
20 changes: 16 additions & 4 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"runtime/pprof"
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -199,8 +200,9 @@ func startInProcess(ctx *Context, cdc codec.JSONMarshaler, appCreator AppCreator
return err
}

config := config.GetConfig()
var apiSrv *api.Server

config := config.GetConfig()
if config.API.Enable {
genDoc, err := genDocProvider()
if err != nil {
Expand All @@ -210,18 +212,28 @@ func startInProcess(ctx *Context, cdc codec.JSONMarshaler, appCreator AppCreator
// TODO: Since this is running in process, do we need to provide a verifier
// and set TrustNode=false? If so, we need to add additional logic that
// waits for a block to be committed first before starting the API server.
ctx := client.Context{}.
clientCtx := client.Context{}.
WithHomeDir(home).
WithChainID(genDoc.ChainID).
WithJSONMarshaler(cdc).
WithClient(local.New(tmNode)).
WithTrustNode(true)

apiSrv = api.New(ctx)
apiSrv = api.New(clientCtx, ctx.Logger.With("module", "api-server"))
app.RegisterAPIRoutes(apiSrv)

if err := apiSrv.Start(config); err != nil {
errCh := make(chan error)

go func() {
if err := apiSrv.Start(config); err != nil {
errCh <- err
}
}()

select {
case err := <-errCh:
return err
case <-time.After(5 * time.Second): // assume server started successfully
}
}

Expand Down
65 changes: 65 additions & 0 deletions testutil/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Package testutil implements and exposes a fully operational in-process Tendermint
test network that consists of at least one or potentially many validators. This
test network can be used primarily for integration tests or unit test suites.
The testnetwork utilizes SimApp as the ABCI application and uses all the modules
defined in the Cosmos SDK. An in-process test network can be configured with any
number of validators as well as account funds and even custom genesis state.
When creating a test network, a series of Validator objects are returned. Each
Validator object has useful information such as their address and pubkey. A
Validator will also provide its RPC, P2P, and API addresses that can be useful
for integration testing. In addition, a Tendermint local RPC client is also provided
which can be handy for making direct RPC calls to Tendermint.
Note, due to limitations in concurrency and the design of the RPC layer in
Tendermint, only the first Validator object will have an RPC and API client
exposed. Due to this exact same limitation, only a single test network can exist
at a time. A caller must be certain it calls Cleanup after it no longer needs
the network.
A typical testing flow might look like the following:
type IntegrationTestSuite struct {
suite.Suite
cfg testutil.Config
network *testutil.Network
}
func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")
cfg := testutil.DefaultConfig()
cfg.NumValidators = 1
s.cfg = cfg
s.network = testutil.NewTestNetwork(s.T(), cfg)
_, err := s.network.WaitForHeight(1)
s.Require().NoError(err)
}
func (s *IntegrationTestSuite) TearDownSuite() {
s.T().Log("tearing down integration test suite")
// This is important and must be called to ensure other tests can create
// a network!
s.network.Cleanup()
}
func (s *IntegrationTestSuite) TestQueryBalancesRequestHandlerFn() {
val := s.network.Validators[0]
baseURL := val.APIAddress
// Use baseURL to make API HTTP requests or use val.RPCClient to make direct
// Tendermint RPC calls.
// ...
}
func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
*/
package testutil
Loading

0 comments on commit 9bf3ff7

Please sign in to comment.