2015-07-21 18:15:40 -04:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
2017-11-08 13:12:48 -05:00
|
|
|
"context"
|
2015-07-21 18:15:40 -04:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2018-07-01 22:36:49 -04:00
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
2017-09-20 18:29:36 -04:00
|
|
|
|
|
|
|
cfg "github.com/tendermint/tendermint/config"
|
2017-11-07 18:08:45 -05:00
|
|
|
"github.com/tendermint/tendermint/types"
|
2015-07-21 18:15:40 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNodeStartStop(t *testing.T) {
|
2017-05-04 22:33:08 -04:00
|
|
|
config := cfg.ResetTestRoot("node_node_test")
|
2015-12-01 20:12:01 -08:00
|
|
|
|
2017-11-07 18:08:45 -05:00
|
|
|
// create & start node
|
2017-09-21 17:08:17 -04:00
|
|
|
n, err := DefaultNewNode(config, log.TestingLogger())
|
|
|
|
assert.NoError(t, err, "expected no err on DefaultNewNode")
|
2017-11-06 13:20:39 -05:00
|
|
|
err1 := n.Start()
|
2017-10-03 19:36:01 -04:00
|
|
|
if err1 != nil {
|
|
|
|
t.Error(err1)
|
|
|
|
}
|
2017-05-02 11:53:32 +04:00
|
|
|
t.Logf("Started node %v", n.sw.NodeInfo())
|
2017-01-15 16:59:10 -08:00
|
|
|
|
2017-11-07 18:08:45 -05:00
|
|
|
// wait for the node to produce a block
|
2017-11-08 13:12:48 -05:00
|
|
|
blockCh := make(chan interface{})
|
|
|
|
err = n.EventBus().Subscribe(context.Background(), "node_test", types.EventQueryNewBlock, blockCh)
|
|
|
|
assert.NoError(t, err)
|
2017-11-07 15:02:42 -05:00
|
|
|
select {
|
2017-11-07 18:08:45 -05:00
|
|
|
case <-blockCh:
|
2018-05-20 16:44:08 -04:00
|
|
|
case <-time.After(10 * time.Second):
|
2017-11-07 18:08:45 -05:00
|
|
|
t.Fatal("timed out waiting for the node to produce a block")
|
2017-11-07 15:02:42 -05:00
|
|
|
}
|
2017-01-15 16:59:10 -08:00
|
|
|
|
2017-11-07 18:08:45 -05:00
|
|
|
// stop the node
|
2015-07-21 18:15:40 -04:00
|
|
|
go func() {
|
|
|
|
n.Stop()
|
|
|
|
}()
|
2017-11-07 15:02:42 -05:00
|
|
|
|
2015-07-21 18:15:40 -04:00
|
|
|
select {
|
2018-02-12 14:31:52 +04:00
|
|
|
case <-n.Quit():
|
2017-11-07 15:02:42 -05:00
|
|
|
case <-time.After(5 * time.Second):
|
2015-07-21 18:15:40 -04:00
|
|
|
t.Fatal("timed out waiting for shutdown")
|
|
|
|
}
|
|
|
|
}
|