MCPcopy Create free account
hub / github.com/CPChain/chain / TestNodeLifeCycle

Function TestNodeLifeCycle

node/node_test.go:30–61  ·  view source on GitHub ↗

Tests that an empty protocol stack can be started, restarted and stopped.

(t *testing.T)

Source from the content-addressed store, hash-verified

28
29// Tests that an empty protocol stack can be started, restarted and stopped.
30func TestNodeLifeCycle(t *testing.T) {
31 stack, err := New(testNodeConfig())
32 if err != nil {
33 t.Fatalf("failed to create protocol stack: %v", err)
34 }
35 // Ensure that a stopped node can be stopped again
36 for i := 0; i < 3; i++ {
37 if err := stack.Stop(); err != ErrNodeStopped {
38 t.Fatalf("iter %d: stop failure mismatch: have %v, want %v", i, err, ErrNodeStopped)
39 }
40 }
41 // Ensure that a node can be successfully started, but only once
42 if err := stack.Start(); err != nil {
43 t.Fatalf("failed to start node: %v", err)
44 }
45 if err := stack.Start(); err != ErrNodeRunning {
46 t.Fatalf("start failure mismatch: have %v, want %v ", err, ErrNodeRunning)
47 }
48 // Ensure that a node can be restarted arbitrarily many times
49 for i := 0; i < 3; i++ {
50 if err := stack.Restart(); err != nil {
51 t.Fatalf("iter %d: failed to restart node: %v", i, err)
52 }
53 }
54 // Ensure that a node can be stopped, but only once
55 if err := stack.Stop(); err != nil {
56 t.Fatalf("failed to stop node: %v", err)
57 }
58 if err := stack.Stop(); err != ErrNodeStopped {
59 t.Fatalf("stop failure mismatch: have %v, want %v ", err, ErrNodeStopped)
60 }
61}
62
63// Tests that if the data dir is already in use, an appropriate error is returned.
64func TestNodeUsedDataDir(t *testing.T) {

Callers

nothing calls this directly

Calls 5

testNodeConfigFunction · 0.85
RestartMethod · 0.80
NewFunction · 0.70
StopMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected