MCPcopy
hub / github.com/grafana/dskit / TestManagerThatFailsToStart

Function TestManagerThatFailsToStart

services/manager_test.go:168–207  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

166}
167
168func TestManagerThatFailsToStart(t *testing.T) {
169 t.Parallel()
170
171 s1 := serviceThatDoesntDoAnything()
172 s2 := serviceThatDoesntDoAnything()
173 s3 := serviceThatFailsToStart()
174 gl := newGatheringManagerListener(t)
175
176 m, err := NewManager(s1, s2, s3)
177 require.NoError(t, err)
178 m.AddListener(gl)
179
180 states := m.ServicesByState()
181 require.Equal(t, states, map[State][]Service{New: {s1, s2, s3}})
182
183 require.NoError(t, m.StartAsync(context.Background()))
184 err = m.AwaitHealthy(context.Background())
185 require.Error(t, err) // will never get healthy, since one service fails to start
186 require.EqualError(t, err, "not healthy, 0 terminated, 1 failed: [failed to start]")
187
188 states = m.ServicesByState()
189 // check that failed state contains s3.
190 require.ElementsMatch(t, states[Failed], []Service{s3})
191
192 // s1 and s2 can be in New (if Starting state transition wasn't observed yet), Starting or Running state.
193 require.ElementsMatch(t, mergeStates(states, New, Starting, Running), []Service{s1, s2})
194
195 // stop remaining services
196 m.StopAsync()
197 require.NoError(t, m.AwaitStopped(context.Background()))
198
199 states = m.ServicesByState()
200 equalStatesMap(t, states, map[State][]Service{
201 Terminated: {s1, s2},
202 Failed: {s3},
203 })
204
205 require.NoError(t, gl.AwaitTerminated(context.Background()))
206 require.Equal(t, []string{"failed", "stopped"}, gl.log)
207}
208
209func TestManagerEntersStopStateEventually(t *testing.T) {
210 t.Parallel()

Callers

nothing calls this directly

Calls 15

AddListenerMethod · 0.95
ServicesByStateMethod · 0.95
StartAsyncMethod · 0.95
AwaitHealthyMethod · 0.95
StopAsyncMethod · 0.95
AwaitStoppedMethod · 0.95
serviceThatFailsToStartFunction · 0.85
mergeStatesFunction · 0.85
equalStatesMapFunction · 0.85
NewManagerFunction · 0.70

Tested by

no test coverage detected