You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

7 years ago
7 years ago
6 years ago
  1. package node
  2. import (
  3. "context"
  4. "fmt"
  5. "os"
  6. "syscall"
  7. "testing"
  8. "time"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/tendermint/tendermint/libs/log"
  11. cfg "github.com/tendermint/tendermint/config"
  12. "github.com/tendermint/tendermint/types"
  13. )
  14. func TestNodeStartStop(t *testing.T) {
  15. config := cfg.ResetTestRoot("node_node_test")
  16. // create & start node
  17. n, err := DefaultNewNode(config, log.TestingLogger())
  18. assert.NoError(t, err, "expected no err on DefaultNewNode")
  19. err1 := n.Start()
  20. if err1 != nil {
  21. t.Error(err1)
  22. }
  23. t.Logf("Started node %v", n.sw.NodeInfo())
  24. // wait for the node to produce a block
  25. blockCh := make(chan interface{})
  26. err = n.EventBus().Subscribe(context.Background(), "node_test", types.EventQueryNewBlock, blockCh)
  27. assert.NoError(t, err)
  28. select {
  29. case <-blockCh:
  30. case <-time.After(10 * time.Second):
  31. t.Fatal("timed out waiting for the node to produce a block")
  32. }
  33. // stop the node
  34. go func() {
  35. n.Stop()
  36. }()
  37. select {
  38. case <-n.Quit():
  39. case <-time.After(5 * time.Second):
  40. pid := os.Getpid()
  41. p, err := os.FindProcess(pid)
  42. if err != nil {
  43. panic(err)
  44. }
  45. err = p.Signal(syscall.SIGABRT)
  46. fmt.Println(err)
  47. t.Fatal("timed out waiting for shutdown")
  48. }
  49. }