(t *testing.T)
| 352 | } |
| 353 | |
| 354 | func TestModuleService_InterruptedFastStartup(t *testing.T) { |
| 355 | finishStarting := make(chan struct{}) |
| 356 | subserviceStarted := make(chan struct{}) |
| 357 | subserviceStopped := false |
| 358 | |
| 359 | subService := services.NewBasicService(func(_ context.Context) error { |
| 360 | // We want to control the execution of this function via the test code, |
| 361 | // so ignore the passed context because it will be cancelled shortly after entering this function. |
| 362 | close(subserviceStarted) |
| 363 | <-finishStarting |
| 364 | return nil |
| 365 | }, func(serviceContext context.Context) error { |
| 366 | <-serviceContext.Done() |
| 367 | return nil |
| 368 | }, func(error) error { |
| 369 | subserviceStopped = true |
| 370 | return nil |
| 371 | }) |
| 372 | |
| 373 | noDepsFunc := func(string) map[string]services.Service { return nil } |
| 374 | moduleSvc := NewModuleService("A", log.NewNopLogger(), subService, noDepsFunc, noDepsFunc) |
| 375 | |
| 376 | ctx, cancel := context.WithCancel(context.Background()) |
| 377 | go func() { |
| 378 | <-subserviceStarted |
| 379 | cancel() |
| 380 | close(finishStarting) |
| 381 | }() |
| 382 | |
| 383 | // Start service using context that's going to be cancelled |
| 384 | require.NoError(t, moduleSvc.StartAsync(ctx)) |
| 385 | // We get context cancelled error from service context cancellation. |
| 386 | err := moduleSvc.AwaitRunning(context.Background()) |
| 387 | require.ErrorIs(t, err, context.Canceled) |
| 388 | require.ErrorContains(t, err, "starting module A") |
| 389 | |
| 390 | require.True(t, subserviceStopped) |
| 391 | require.Equal(t, services.Failed, moduleSvc.State()) |
| 392 | require.Equal(t, services.Terminated, subService.State()) |
| 393 | } |
| 394 | |
| 395 | func TestModuleService_InterruptedSlowStartup(t *testing.T) { |
| 396 | subserviceStarted := make(chan struct{}) |
nothing calls this directly
no test coverage detected