MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestManagerThatFailsToStart

Function TestManagerThatFailsToStart

pkg/util/services/manager_test.go:164–203  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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