tendermint/node/node_test.go

59 lines
1.2 KiB
Go
Raw Normal View History

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