(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func TestResyncWithoutIndexes(t *testing.T) { |
| 22 | base.TestRequiresDCPResync(t) |
| 23 | rt := rest.NewRestTester(t, &rest.RestTesterConfig{ |
| 24 | PersistentConfig: true}) |
| 25 | defer rt.Close() |
| 26 | |
| 27 | dbName := "db" |
| 28 | |
| 29 | // CBG-4615: parametrize test to use legacy sync docs index, or users and roles indexes |
| 30 | rest.RequireStatus(t, rt.CreateDatabase(dbName, rt.NewDbConfig()), http.StatusCreated) |
| 31 | // create test doc to change sequence number |
| 32 | rt.CreateTestDoc("doc1") |
| 33 | |
| 34 | rt.SyncFn = `function(doc, oldDoc) {channel("A")}` |
| 35 | rest.RequireStatus(t, rt.UpsertDbConfig(dbName, rt.NewDbConfig()), http.StatusCreated) |
| 36 | |
| 37 | rt.TakeDbOffline() |
| 38 | |
| 39 | if !base.TestsDisableGSI() { |
| 40 | for _, collection := range rt.GetDatabase().CollectionByID { |
| 41 | n1qlStore, ok := base.AsN1QLStore(collection.GetCollectionDatastore()) |
| 42 | require.True(t, ok) |
| 43 | require.NoError(t, base.DropAllIndexes(rt.Context(), n1qlStore)) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // gocb pipeline bootstrap errors can occur before this stage |
| 48 | warningsBeforeResync := base.SyncGatewayStats.GlobalStats.ResourceUtilization.WarnCount.Value() |
| 49 | rest.RequireStatus(t, rt.SendAdminRequest(http.MethodPost, "/{{.db}}/_resync?action=start", ""), http.StatusOK) |
| 50 | resyncStatus := rt.WaitForResyncDCPStatus(db.BackgroundProcessStateCompleted) |
| 51 | require.Equal(t, int64(1), resyncStatus.DocsChanged) |
| 52 | require.Equal(t, int64(0), base.SyncGatewayStats.GlobalStats.ResourceUtilization.WarnCount.Value()-warningsBeforeResync) |
| 53 | |
| 54 | defaultDataStore, ok := base.AsN1QLStore(rt.Bucket().DefaultDataStore()) |
| 55 | require.True(t, ok) |
| 56 | |
| 57 | if !base.TestsDisableGSI() { |
| 58 | numIndexes, err := defaultDataStore.GetIndexes() |
| 59 | require.NoError(t, err) |
| 60 | if rt.GetDatabase().UseLegacySyncDocsIndex() { |
| 61 | require.Len(t, numIndexes, 1) // sg_syncDocs |
| 62 | } else { |
| 63 | require.Len(t, numIndexes, 2) // sg_roles, sg_syncDocs |
| 64 | } |
| 65 | |
| 66 | for _, collection := range rt.GetDatabase().CollectionByID { |
| 67 | n1qlStore, ok := base.AsN1QLStore(collection.GetCollectionDatastore()) |
| 68 | require.True(t, ok) |
| 69 | numIndexes, err := n1qlStore.GetIndexes() |
| 70 | require.NoError(t, err) |
| 71 | if collection.IsDefaultCollection() { |
| 72 | if rt.GetDatabase().UseLegacySyncDocsIndex() { |
| 73 | require.Len(t, numIndexes, 1) // sg_syncDocs |
| 74 | } else { |
| 75 | require.Len(t, numIndexes, 2) // sg_roles, sg_syncDocs |
| 76 | } |
| 77 | } else { |
| 78 | require.Len(t, numIndexes, 0, "Expected 0 indexes for non-default collection") |
nothing calls this directly
no test coverage detected