(t *testing.T)
| 38 | ) |
| 39 | |
| 40 | func TestNodeStartStop(t *testing.T) { |
| 41 | cfg, err := config.ResetTestRoot("node_node_test") |
| 42 | require.NoError(t, err) |
| 43 | |
| 44 | defer os.RemoveAll(cfg.RootDir) |
| 45 | |
| 46 | // create & start node |
| 47 | ns, err := newDefaultNode(cfg, log.TestingLogger()) |
| 48 | require.NoError(t, err) |
| 49 | require.NoError(t, ns.Start()) |
| 50 | |
| 51 | n, ok := ns.(*nodeImpl) |
| 52 | require.True(t, ok) |
| 53 | |
| 54 | // wait for the node to produce a block |
| 55 | blocksSub, err := n.EventBus().Subscribe(context.Background(), "node_test", types.EventQueryNewBlock) |
| 56 | require.NoError(t, err) |
| 57 | select { |
| 58 | case <-blocksSub.Out(): |
| 59 | case <-blocksSub.Canceled(): |
| 60 | t.Fatal("blocksSub was canceled") |
| 61 | case <-time.After(10 * time.Second): |
| 62 | t.Fatal("timed out waiting for the node to produce a block") |
| 63 | } |
| 64 | |
| 65 | // stop the node |
| 66 | go func() { |
| 67 | err = n.Stop() |
| 68 | require.NoError(t, err) |
| 69 | }() |
| 70 | |
| 71 | select { |
| 72 | case <-n.Quit(): |
| 73 | case <-time.After(5 * time.Second): |
| 74 | pid := os.Getpid() |
| 75 | p, err := os.FindProcess(pid) |
| 76 | if err != nil { |
| 77 | panic(err) |
| 78 | } |
| 79 | err = p.Signal(syscall.SIGABRT) |
| 80 | fmt.Println(err) |
| 81 | t.Fatal("timed out waiting for shutdown") |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | func getTestNode(t *testing.T, conf *config.Config, logger log.Logger) *nodeImpl { |
| 86 | t.Helper() |
nothing calls this directly
no test coverage detected
searching dependent graphs…