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

Function TestDatabaseInitTeardownTiming

rest/database_init_manager_test.go:417–482  ·  view source on GitHub ↗

TestDatabaseInitTeardownTiming tests scenarios where InitializeDatabase is called during the completion phase of a previous async initialization. Ensures there are no cases where a watcher is added but never receives a done notification.

(t *testing.T)

Source from the content-addressed store, hash-verified

415// the completion phase of a previous async initialization. Ensures there are no cases where a
416// watcher is added but never receives a done notification.
417func TestDatabaseInitTeardownTiming(t *testing.T) {
418
419 RequireN1QLIndexes(t)
420 base.TestRequiresCollections(t)
421 base.SetUpTestLogging(t, base.LevelInfo, base.KeyHTTP, base.KeyConfig)
422
423 sc, closeFn := StartBootstrapServer(t)
424 defer closeFn()
425 ctx := base.TestCtx(t)
426
427 // Get a test bucket for bootstrap testing, and drop indexes created by bucket pool readier
428 tb := base.GetTestBucket(t)
429 defer tb.Close(ctx)
430
431 // Drop all test indexes so we can test InitializeDatabase
432 DropAllTestIndexes(t, tb)
433
434 // Set up collection names and ScopesConfig for testing
435 scopesConfig := GetCollectionsConfig(t, tb, 3)
436 dataStoreNames := GetDataStoreNamesFromScopesConfig(scopesConfig)
437 scopeName := dataStoreNames[0].ScopeName()
438 collection1Name := dataStoreNames[0].CollectionName()
439 collection2Name := dataStoreNames[1].CollectionName()
440 collection1and2ScopesConfig := makeScopesConfig(scopeName, []string{collection1Name, collection2Name})
441
442 initMgr := sc.DatabaseInitManager
443
444 // Create collection callback that blocks and waits for test notification the first time a collection is initialized, does not block afterward.
445 var collectionCount atomic.Int64
446 initMgr.testCollectionStatusUpdateCallback = func(_ string, _ base.ScopeAndCollectionName, status db.CollectionIndexStatus) {
447 if status != db.CollectionIndexStatusReady {
448 return
449 }
450 collectionCount.Add(1)
451 }
452 dbName := "dbName"
453 dbConfig := makeDbConfig(tb.GetName(), dbName, collection1and2ScopesConfig)
454 require.NoError(t, dbConfig.setup(ctx, dbName, sc.Config.Bootstrap, nil, nil, false))
455
456 wg := &sync.WaitGroup{}
457 wg.Add(1)
458 var databaseCompleteCount atomic.Int64
459 initMgr.testDatabaseCompleteCallback = func(dbName string) {
460 // On first completion, invoke InitializeDatabase with the same collection set post-completion
461 if databaseCompleteCount.Add(1) == 1 {
462 defer wg.Done()
463 log.Printf("invoking InitializeDatabase again during teardown")
464 doneChan2, err := initMgr.InitializeDatabase(ctx, sc.Config, dbConfig.ToDatabaseConfig(), testUseLegacySyncDocsIndex)
465 require.NoError(t, err)
466 WaitForChannel(t, doneChan2, "done chan 2")
467 }
468 }
469
470 // Start first async index creation, should block after first collection
471 doneChan1, err := initMgr.InitializeDatabase(ctx, sc.Config, dbConfig.ToDatabaseConfig(), testUseLegacySyncDocsIndex)
472 require.NoError(t, err)
473
474 WaitForChannel(t, doneChan1, "done chan 1")

Callers

nothing calls this directly

Calls 15

TestRequiresCollectionsFunction · 0.92
SetUpTestLoggingFunction · 0.92
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
RequireN1QLIndexesFunction · 0.85
StartBootstrapServerFunction · 0.85
DropAllTestIndexesFunction · 0.85
GetCollectionsConfigFunction · 0.85
makeScopesConfigFunction · 0.85
WaitForChannelFunction · 0.85
setupMethod · 0.80

Tested by

no test coverage detected