Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Network Testing Framework #6489

Merged
merged 39 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c9d5b34
Init commit
alexanderbez Jun 23, 2020
1e651e8
Remove script
alexanderbez Jun 23, 2020
9d8494f
Merge branch 'master' into bez/in-process-test-framework
alexanderbez Jun 23, 2020
cd2ec2d
Fix IBC codec bug
alexanderbez Jun 23, 2020
ecfa3c8
go mod tidy + codec fixes attempt
alexanderbez Jun 23, 2020
c7e9b60
Change base dir to use chain-id
alexanderbez Jun 23, 2020
f5deb8d
Add trap signal call
alexanderbez Jun 23, 2020
7f51e12
Add godoc
alexanderbez Jun 23, 2020
b7c2cca
Merge branch 'master' into bez/in-process-test-framework
alexanderbez Jun 23, 2020
ec88212
Updates
alexanderbez Jun 23, 2020
4f43424
Tweaks
alexanderbez Jun 23, 2020
e8f5176
Fix fn name
alexanderbez Jun 23, 2020
433b67e
Cleanup
alexanderbez Jun 23, 2020
f7758f7
Only allow 1st val to serve rpc/api
alexanderbez Jun 24, 2020
4bc56bd
use pkg lock
alexanderbez Jun 24, 2020
d430884
Merge branch 'master' into bez/in-process-test-framework
alexanderbez Jun 24, 2020
c389c81
lint++
alexanderbez Jun 24, 2020
a6f8fe3
lint++
alexanderbez Jun 24, 2020
9442a8b
Remove use of errgroup
alexanderbez Jun 24, 2020
0aff4e4
ci: remove -race flag from tests
alexanderbez Jun 24, 2020
69603bc
Merge branch 'master' into bez/in-process-test-framework
alexanderbez Jun 24, 2020
6d1719f
Add doc
alexanderbez Jun 25, 2020
c53831d
Merge branch 'master' into bez/in-process-test-framework
alexanderbez Jun 25, 2020
ff14f0d
Merge branch 'master' into bez/in-process-test-framework
fedekunze Jun 25, 2020
93454e5
cl++
alexanderbez Jun 25, 2020
52aa585
Add section to godoc
alexanderbez Jun 25, 2020
f889a0b
testutil: address comments
alexanderbez Jun 25, 2020
cdc9db6
Update testutil/doc.go
alexanderbez Jun 25, 2020
8aa5c71
Update testutil/doc.go
alexanderbez Jun 25, 2020
426505e
Update testutil/doc.go
alexanderbez Jun 25, 2020
c6a208a
testutil: make app confiruable
alexanderbez Jun 26, 2020
05fd4a7
testutil: update go doc
alexanderbez Jun 26, 2020
38aac75
Merge branch 'bez/in-process-test-framework' of github.com:cosmos/cos…
alexanderbez Jun 26, 2020
195447e
testutil: revise app con
alexanderbez Jun 26, 2020
939b6c3
testutil: update go doc
alexanderbez Jun 26, 2020
9c77941
Fixes
alexanderbez Jun 26, 2020
89a447d
Merge branch 'master' into bez/in-process-test-framework
alexanderbez Jun 26, 2020
df0b1b6
Merge branch 'master' into bez/in-process-test-framework
mergify[bot] Jun 26, 2020
ddb342b
Merge branch 'master' into bez/in-process-test-framework
mergify[bot] Jun 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -40,6 +40,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 @@ -609,6 +609,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
Comment on lines -223 to +236
Copy link
Contributor Author

@alexanderbez alexanderbez Jun 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not realize Tendermint HTTP client actually blocks -- this fixes that so we can properly cleanup below.

}
}

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 objects has useful information such as their address and pubkey. A
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
Validator will also provide its RPC, P2P, and API addresses that can be useful
for integration testing. In addition, a Tendermint local RPC client also provided
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
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 objects will have an RPC and API client
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
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