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

Function TestServiceRegistry

node/node_test.go:93–122  ·  view source on GitHub ↗

Tests whether services can be registered and duplicates caught.

(t *testing.T)

Source from the content-addressed store, hash-verified

91
92// Tests whether services can be registered and duplicates caught.
93func TestServiceRegistry(t *testing.T) {
94 stack, err := New(testNodeConfig())
95 if err != nil {
96 t.Fatalf("failed to create protocol stack: %v", err)
97 }
98 // Register a batch of unique services and ensure they start successfully
99 services := []ServiceConstructor{NewNoopServiceA, NewNoopServiceB, NewNoopServiceC}
100 for i, constructor := range services {
101 if err := stack.Register(constructor); err != nil {
102 t.Fatalf("service #%d: registration failed: %v", i, err)
103 }
104 }
105 if err := stack.Start(); err != nil {
106 t.Fatalf("failed to start original service stack: %v", err)
107 }
108 if err := stack.Stop(); err != nil {
109 t.Fatalf("failed to stop original service stack: %v", err)
110 }
111 // Duplicate one of the services and retry starting the node
112 if err := stack.Register(NewNoopServiceB); err != nil {
113 t.Fatalf("duplicate registration failed: %v", err)
114 }
115 if err := stack.Start(); err == nil {
116 t.Fatalf("duplicate service started")
117 } else {
118 if _, ok := err.(*DuplicateServiceError); !ok {
119 t.Fatalf("duplicate error mismatch: have %v, want %v", err, DuplicateServiceError{})
120 }
121 }
122}
123
124// Tests that registered services get started and stopped correctly.
125func TestServiceLifeCycle(t *testing.T) {

Callers

nothing calls this directly

Calls 5

testNodeConfigFunction · 0.85
NewFunction · 0.70
StartMethod · 0.65
StopMethod · 0.65
RegisterMethod · 0.45

Tested by

no test coverage detected