Tests whether services can be registered and duplicates caught.
(t *testing.T)
| 91 | |
| 92 | // Tests whether services can be registered and duplicates caught. |
| 93 | func 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. |
| 125 | func TestServiceLifeCycle(t *testing.T) { |
nothing calls this directly
no test coverage detected