MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / Test_waitForBackgroundManagersToStop

Function Test_waitForBackgroundManagersToStop

db/database_test.go:4460–4531  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4458}
4459
4460func Test_waitForBackgroundManagersToStop(t *testing.T) {
4461 // use testing/synctest to have fake time once go 1.25 is available. In the meantime, windows and -race are
4462 // slow enough thatthe time is increased, but this keeps interactive testing fast.
4463 waitTime := 50 * time.Millisecond
4464 if runtime.GOOS == "windows" || base.IsRaceDetectorEnabled(t) {
4465 waitTime = 1 * time.Second
4466 }
4467 t.Run("single unstoppable process", func(t *testing.T) {
4468 bgMngr := &BackgroundManager{
4469 name: "test_unstoppable_runner",
4470 Process: &testBackgroundProcess{isStoppable: false},
4471 }
4472 ctx := base.TestCtx(t)
4473 err := bgMngr.Start(ctx, map[string]interface{}{})
4474 require.NoError(t, err)
4475 err = bgMngr.Stop()
4476 require.NoError(t, err)
4477
4478 startTime := time.Now()
4479 deadline := waitTime
4480 waitForBackgroundManagersToStop(ctx, deadline, []*BackgroundManager{bgMngr})
4481 assert.Greater(t, time.Since(startTime), deadline)
4482 assert.Equal(t, BackgroundProcessStateStopping, bgMngr.GetRunState())
4483 })
4484
4485 t.Run("single stoppable process", func(t *testing.T) {
4486 bgMngr := &BackgroundManager{
4487 name: "test_stoppable_runner",
4488 Process: &testBackgroundProcess{isStoppable: true},
4489 }
4490 ctx := base.TestCtx(t)
4491 err := bgMngr.Start(ctx, map[string]interface{}{})
4492 require.NoError(t, err)
4493 err = bgMngr.Stop()
4494 require.NoError(t, err)
4495
4496 startTime := time.Now()
4497 deadline := waitTime
4498 waitForBackgroundManagersToStop(ctx, deadline, []*BackgroundManager{bgMngr})
4499 assert.Less(t, time.Since(startTime), deadline)
4500 assert.Equal(t, BackgroundProcessStateStopped, bgMngr.GetRunState())
4501 })
4502
4503 t.Run("one stoppable process and one unstoppable process", func(t *testing.T) {
4504 stoppableBgMngr := &BackgroundManager{
4505 name: "test_stoppable_runner",
4506 Process: &testBackgroundProcess{isStoppable: true},
4507 }
4508 ctx := base.TestCtx(t)
4509 err := stoppableBgMngr.Start(ctx, map[string]interface{}{})
4510 require.NoError(t, err)
4511 err = stoppableBgMngr.Stop()
4512 require.NoError(t, err)
4513
4514 unstoppableBgMngr := &BackgroundManager{
4515 name: "test_unstoppable_runner",
4516 Process: &testBackgroundProcess{isStoppable: false},
4517 }

Callers

nothing calls this directly

Calls 10

StartMethod · 0.95
StopMethod · 0.95
GetRunStateMethod · 0.95
IsRaceDetectorEnabledFunction · 0.92
TestCtxFunction · 0.92
RunMethod · 0.65
SinceMethod · 0.45
EqualMethod · 0.45
LessMethod · 0.45

Tested by

no test coverage detected