2015-07-21 18:15:40 -04:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2017-05-02 11:53:32 +04:00
|
|
|
"github.com/tendermint/tmlibs/log"
|
2017-09-20 18:29:36 -04:00
|
|
|
|
|
|
|
cfg "github.com/tendermint/tendermint/config"
|
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
|
|
|
|
2015-07-21 18:15:40 -04:00
|
|
|
// Create & start node
|
2017-09-20 18:29:36 -04:00
|
|
|
n, err := NewNodeDefault(config, log.TestingLogger())
|
|
|
|
assert.NoError(t, err, "expected no err on NewNodeDefault")
|
2015-07-21 18:15:40 -04:00
|
|
|
n.Start()
|
2017-05-02 11:53:32 +04:00
|
|
|
t.Logf("Started node %v", n.sw.NodeInfo())
|
2017-01-15 16:59:10 -08:00
|
|
|
|
|
|
|
// Wait a bit to initialize
|
|
|
|
// TODO remove time.Sleep(), make asynchronous.
|
2015-07-21 18:15:40 -04:00
|
|
|
time.Sleep(time.Second * 2)
|
2017-01-15 16:59:10 -08:00
|
|
|
|
2015-07-21 18:15:40 -04:00
|
|
|
ch := make(chan struct{}, 1)
|
|
|
|
go func() {
|
|
|
|
n.Stop()
|
|
|
|
ch <- struct{}{}
|
|
|
|
}()
|
|
|
|
ticker := time.NewTicker(time.Second * 5)
|
|
|
|
select {
|
|
|
|
case <-ch:
|
|
|
|
case <-ticker.C:
|
|
|
|
t.Fatal("timed out waiting for shutdown")
|
|
|
|
}
|
|
|
|
}
|