Merge PR #6489: Test Network Testing Framework

This commit is contained in:
Alexander Bezobchuk
2020-06-26 12:30:49 -04:00
committed by GitHub
parent 3df4dd0cd9
commit 9bf3ff75f5
19 changed files with 883 additions and 115 deletions
+2 -3
View File
@@ -4,7 +4,6 @@ import (
"fmt"
"net"
"net/http"
"os"
"strings"
"time"
@@ -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,
}
}
+16 -4
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"os"
"runtime/pprof"
"time"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -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 {
@@ -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
}
}