Skip to content

Commit

Permalink
server: remove broken start test
Browse files Browse the repository at this point in the history
  • Loading branch information
ebuchman committed Jul 2, 2018
1 parent dbabc2e commit 0845d81
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 60 deletions.
13 changes: 7 additions & 6 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func StartCmd(ctx *Context, appCreator AppCreator) *cobra.Command {
return startStandAlone(ctx, appCreator)
}
ctx.Logger.Info("Starting ABCI with Tendermint")
return startInProcess(ctx, appCreator)
_, err := startInProcess(ctx, appCreator)
return err
},
}

Expand Down Expand Up @@ -74,12 +75,12 @@ func startStandAlone(ctx *Context, appCreator AppCreator) error {
return nil
}

func startInProcess(ctx *Context, appCreator AppCreator) error {
func startInProcess(ctx *Context, appCreator AppCreator) (*node.Node, error) {
cfg := ctx.Config
home := cfg.RootDir
app, err := appCreator(home, ctx.Logger)
if err != nil {
return err
return nil, err
}

// Create & start tendermint node
Expand All @@ -91,15 +92,15 @@ func startInProcess(ctx *Context, appCreator AppCreator) error {
node.DefaultMetricsProvider,
ctx.Logger.With("module", "node"))
if err != nil {
return err
return nil, err
}

err = n.Start()
if err != nil {
return err
return nil, err
}

// Trap signal, run forever.
n.RunForever()
return nil
return n, nil
}
31 changes: 1 addition & 30 deletions server/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"
"time"

"github.com/spf13/viper"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/server/mock"
Expand Down Expand Up @@ -45,37 +44,9 @@ func TestStartStandAlone(t *testing.T) {
svr.SetLogger(logger.With("module", "abci-server"))
svr.Start()

timer := time.NewTimer(time.Duration(5) * time.Second)
timer := time.NewTimer(time.Duration(2) * time.Second)
select {
case <-timer.C:
svr.Stop()
}
}

func TestStartWithTendermint(t *testing.T) {
defer setupViper(t)()

logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).
With("module", "mock-cmd")
cfg, err := tcmd.ParseConfig()
require.Nil(t, err)
ctx := NewContext(cfg, logger)
cdc := wire.NewCodec()
appInit := AppInit{
AppGenState: mock.AppGenState,
AppGenTx: mock.AppGenTx,
}
initCmd := InitCmd(ctx, cdc, appInit)
err = initCmd.RunE(nil, nil)
require.NoError(t, err)

// set up app and start up
viper.Set(flagWithTendermint, true)
startCmd := StartCmd(ctx, mock.NewApp)
svrAddr, _, err := FreeTCPAddr()
require.NoError(t, err)
startCmd.Flags().Set(flagAddress, svrAddr) // set to a new free address
timeout := time.Duration(5) * time.Second

close(RunOrTimeout(startCmd, timeout, t))
}
24 changes: 0 additions & 24 deletions server/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"net"
"os"
"testing"
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"github.com/tendermint/tmlibs/cli"
Expand Down Expand Up @@ -52,25 +50,3 @@ func setupViper(t *testing.T) func() {
}
}
}

// Run or Timout RunE of command passed in
func RunOrTimeout(cmd *cobra.Command, timeout time.Duration, t *testing.T) chan error {
done := make(chan error)
go func(out chan<- error) {
// this should NOT exit
err := cmd.RunE(nil, nil)
if err != nil {
out <- err
}
out <- fmt.Errorf("start died for unknown reasons")
}(done)
timer := time.NewTimer(timeout)

select {
case err := <-done:
require.NoError(t, err)
case <-timer.C:
return done
}
return done
}

0 comments on commit 0845d81

Please sign in to comment.