(t *testing.T)
| 393 | } |
| 394 | |
| 395 | func 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 | |
| 430 | func getStopDependenciesForModule(module string, services map[string]services.Service) []string { |
| 431 | var deps []string |
nothing calls this directly
no test coverage detected