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

Function TestModuleService_InterruptedSlowStartup

modules/modules_test.go:395–428  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

393}
394
395func TestModuleService_InterruptedSlowStartup(t *testing.T) {
396 subserviceStarted := make(chan struct{})
397 subserviceStopped := false
398
399 subService := services.NewBasicService(func(serviceContext context.Context) error {
400 close(subserviceStarted)
401 // Prolong the startup until we have to stop.
402 <-serviceContext.Done()
403 return nil
404 }, func(context.Context) error {
405 require.Fail(t, "did not expect to enter running state; service should have been canceled while in starting Fn and go directly to stoppingFn")
406 return nil
407 }, func(error) error {
408 subserviceStopped = true
409 return nil
410 })
411
412 noDepsFunc := func(string) map[string]services.Service { return nil }
413 moduleSvc := NewModuleService("A", log.NewNopLogger(), subService, noDepsFunc, noDepsFunc)
414
415 // Don't wait for startup because it will be very slow.
416 require.NoError(t, moduleSvc.StartAsync(context.Background()))
417
418 <-subserviceStarted
419
420 // We get context.Canceled from moduleService.start.
421 err := services.StopAndAwaitTerminated(context.Background(), moduleSvc)
422 require.ErrorIs(t, err, context.Canceled)
423 require.ErrorContains(t, err, "starting module A")
424
425 assert.True(t, subserviceStopped)
426 require.Equal(t, services.Failed, moduleSvc.State())
427 require.Equal(t, services.Terminated, subService.State())
428}
429
430func getStopDependenciesForModule(module string, services map[string]services.Service) []string {
431 var deps []string

Callers

nothing calls this directly

Calls 9

StateMethod · 0.95
NewBasicServiceFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
NewModuleServiceFunction · 0.85
FailMethod · 0.80
DoneMethod · 0.65
StartAsyncMethod · 0.65
StateMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected