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

Function TestManagerAwaitWithContextCancellation

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

Source from the content-addressed store, hash-verified

230}
231
232func TestManagerAwaitWithContextCancellation(t *testing.T) {
233 t.Parallel()
234
235 s1 := serviceThatStopsOnItsOwnAfterTimeout(200 * time.Millisecond)
236 s2 := serviceThatStopsOnItsOwnAfterTimeout(300 * time.Millisecond)
237 gl := newGatheringManagerListener(t)
238
239 m, err := NewManager(s1, s2)
240 require.NoError(t, err)
241 m.AddListener(gl)
242
243 // test context cancellation
244 stoppedContext, cancel := context.WithCancel(context.Background())
245 cancel()
246
247 require.Equal(t, context.Canceled, m.AwaitHealthy(stoppedContext)) // since no services have started yet, and context is stopped, must return error quickly
248
249 // start all services
250 require.NoError(t, m.StartAsync(context.Background()))
251
252 shortContext, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
253 defer cancel()
254
255 require.Equal(t, context.DeadlineExceeded, m.AwaitStopped(shortContext))
256 require.NoError(t, m.AwaitStopped(context.Background()))
257
258 require.NoError(t, gl.AwaitTerminated(context.Background()))
259 require.Equal(t, []string{"healthy", "stopped"}, gl.log)
260}
261
262func mergeStates(m map[State][]Service, states ...State) []Service {
263 result := []Service(nil)

Callers

nothing calls this directly

Calls 9

AddListenerMethod · 0.95
AwaitHealthyMethod · 0.95
StartAsyncMethod · 0.95
AwaitStoppedMethod · 0.95
NewManagerFunction · 0.70
AwaitTerminatedMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected