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

Function TestDatabaseInitManager

rest/database_init_manager_test.go:27–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25const testUseLegacySyncDocsIndex = false
26
27func TestDatabaseInitManager(t *testing.T) {
28 RequireN1QLIndexes(t)
29
30 sc, closeFn := StartBootstrapServer(t)
31 defer closeFn()
32
33 initMgr := sc.DatabaseInitManager
34
35 ctx := base.TestCtx(t)
36 // Get a test bucket for bootstrap testing, and create dbconfig targeting that bucket
37 tb := base.GetTestBucket(t)
38 defer tb.Close(ctx)
39 dbName := "dbName"
40 var scopesConfig ScopesConfig
41 if base.TestsUseNamedCollections() {
42 scopesConfig = GetCollectionsConfig(t, tb, 1)
43 }
44 dbConfig := makeDbConfig(tb.GetName(), dbName, scopesConfig)
45 require.NoError(t, dbConfig.setup(ctx, dbName, sc.Config.Bootstrap, nil, nil, false))
46
47 // Drop indexes
48 dropAllNonPrimaryIndexes(t, tb.GetSingleDataStore())
49
50 // Async index creation
51 doneChan, err := initMgr.InitializeDatabase(ctx, sc.Config, dbConfig.ToDatabaseConfig(), testUseLegacySyncDocsIndex)
52 require.NoError(t, err)
53
54 select {
55 case err := <-doneChan:
56 require.NoError(t, err)
57 case <-time.After(30 * time.Second):
58 require.Fail(t, "InitializeDatabase didn't complete in 30s")
59 }
60
61}
62
63// TestDatabaseInitConfigChangeSameCollections tests modifications made to the database config while init is running.
64// Uses initManager callbacks to simulate slow index creation and build. Tests the following two scenarios:

Callers

nothing calls this directly

Calls 15

TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
TestsUseNamedCollectionsFunction · 0.92
RequireN1QLIndexesFunction · 0.85
StartBootstrapServerFunction · 0.85
GetCollectionsConfigFunction · 0.85
dropAllNonPrimaryIndexesFunction · 0.85
setupMethod · 0.80
InitializeDatabaseMethod · 0.80
ToDatabaseConfigMethod · 0.80
AfterMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected