MCPcopy Index your code
hub / github.com/riverqueue/river / TestStartAll

Function TestStartAll

rivershared/startstop/start_stop_test.go:445–510  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

443}
444
445func TestStartAll(t *testing.T) {
446 t.Parallel()
447
448 ctx := context.Background()
449
450 t.Run("StartsAllServices", func(t *testing.T) {
451 t.Parallel()
452
453 var (
454 service1 = &sampleService{}
455 service2 = &sampleService{}
456 service3 = &sampleService{}
457 )
458
459 t.Cleanup(service1.Stop)
460 t.Cleanup(service2.Stop)
461 t.Cleanup(service3.Stop)
462
463 err := StartAll(ctx, service1, service2, service3)
464 require.NoError(t, err)
465
466 riversharedtest.WaitOrTimeout(t, WaitAllStartedC(service1, service2, service3))
467 })
468
469 t.Run("ReturnsFirstError", func(t *testing.T) {
470 t.Parallel()
471
472 var (
473 service1 = &sampleService{}
474 service2 = &sampleService{}
475 service3 = &sampleService{startErr: errors.New("a start error")}
476 )
477
478 t.Cleanup(service1.Stop)
479 t.Cleanup(service2.Stop)
480 t.Cleanup(service3.Stop)
481
482 // References must be invoked before anything is stopped.
483 var (
484 stopped1 = service1.Stopped()
485 stopped2 = service2.Stopped()
486 )
487
488 err := StartAll(ctx, service1, service2, service3)
489 require.EqualError(t, err, "a start error")
490
491 // The first two services should have been stopped after the third
492 // service failed to start.
493 riversharedtest.WaitOrTimeout(t, stopped1)
494 riversharedtest.WaitOrTimeout(t, stopped2)
495 })
496
497 // Same as the above except with only a single service. Exists to make sure
498 // that there's nothing wrong with the way we're indexing a slice of
499 // services when stopping on error.
500 t.Run("ErrorWithOneService", func(t *testing.T) {
501 t.Parallel()
502

Callers

nothing calls this directly

Calls 6

WaitOrTimeoutFunction · 0.92
StartAllFunction · 0.85
WaitAllStartedCFunction · 0.85
CleanupMethod · 0.80
RunMethod · 0.65
StoppedMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…