Skip to content

Commit

Permalink
refactor(network): call app.Close() on network cleanup (#18249)
Browse files Browse the repository at this point in the history
(cherry picked from commit 139a29e)
  • Loading branch information
julienrbrt authored and mergify[bot] committed Oct 25, 2023
1 parent 06dacdc commit f9d672a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 8 additions & 2 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ type (
ValAddress sdk.ValAddress
RPCClient cmtclient.Client

app servertypes.Application
tmNode *node.Node
api *api.Server
grpc *grpc.Server
Expand Down Expand Up @@ -611,8 +612,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {

l.Log("starting test network...")
for idx, v := range network.Validators {
err := startInProcess(cfg, v)
if err != nil {
if err := startInProcess(cfg, v); err != nil {
return nil, err
}
l.Log("started validator", idx)
Expand Down Expand Up @@ -803,6 +803,12 @@ func (n *Network) Cleanup() {
if v.grpcWeb != nil {
_ = v.grpcWeb.Close()
}

if v.app != nil {
if err := v.app.Close(); err != nil {
n.Logger.Log("failed to stop validator ABCI application", "err", err)
}
}
}

time.Sleep(100 * time.Millisecond)
Expand Down
8 changes: 6 additions & 2 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
cmttime "github.com/cometbft/cometbft/types/time"
"golang.org/x/sync/errgroup"

"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/api"
servergrpc "github.com/cosmos/cosmos-sdk/server/grpc"
Expand All @@ -43,6 +45,8 @@ func startInProcess(cfg Config, val *Validator) error {
}

app := cfg.AppConstructor(*val)
val.app = app

appGenesisProvider := func() (*cmttypes.GenesisDoc, error) {
appGenesis, err := genutiltypes.AppGenesisFromFile(cmtCfg.GenesisFile())
if err != nil {
Expand Down Expand Up @@ -101,14 +105,14 @@ func startInProcess(cfg Config, val *Validator) error {
// Start the gRPC server in a goroutine. Note, the provided ctx will ensure
// that the server is gracefully shut down.
val.errGroup.Go(func() error {
return servergrpc.StartGRPCServer(ctx, logger.With("module", "grpc-server"), grpcCfg, grpcSrv)
return servergrpc.StartGRPCServer(ctx, logger.With(log.ModuleKey, "grpc-server"), grpcCfg, grpcSrv)
})

val.grpc = grpcSrv
}

if val.APIAddress != "" {
apiSrv := api.New(val.ClientCtx, logger.With("module", "api-server"), val.grpc)
apiSrv := api.New(val.ClientCtx, logger.With(log.ModuleKey, "api-server"), val.grpc)
app.RegisterAPIRoutes(apiSrv, val.AppConfig.API)

val.errGroup.Go(func() error {
Expand Down

0 comments on commit f9d672a

Please sign in to comment.