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

Function Test_resyncDocument

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

Source from the content-addressed store, hash-verified

4033}
4034
4035func Test_resyncDocument(t *testing.T) {
4036 db, ctx := setupTestDB(t)
4037 defer db.Close(ctx)
4038
4039 db.Options.EnableXattr = true
4040 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
4041
4042 testCases := []struct {
4043 name string
4044 useHLV bool
4045 }{
4046 {
4047 name: "pre 4.0",
4048 useHLV: false,
4049 },
4050 {
4051 name: "has hlv",
4052 useHLV: true,
4053 },
4054 }
4055
4056 for _, tc := range testCases {
4057 t.Run(tc.name, func(t *testing.T) {
4058 startingSyncFnCount := int(db.DbStats.Database().SyncFunctionCount.Value())
4059 syncFn := `
4060 function sync(doc, oldDoc){
4061 channel("channel." + "ABC");
4062 }
4063`
4064 _, err := collection.UpdateSyncFun(ctx, syncFn)
4065 require.NoError(t, err)
4066
4067 docID := uuid.NewString()
4068
4069 updateBody := make(map[string]any)
4070 updateBody["val"] = "value"
4071 if tc.useHLV {
4072 _, _, err := collection.Put(ctx, docID, updateBody)
4073 require.NoError(t, err)
4074 } else {
4075 collection.CreateDocNoHLV(t, ctx, docID, updateBody)
4076 }
4077
4078 syncFn = `
4079 function sync(doc, oldDoc){
4080 channel("channel." + "ABC12332423234");
4081 }
4082 `
4083 _, err = collection.UpdateSyncFun(ctx, syncFn)
4084 require.NoError(t, err)
4085
4086 preResyncDoc, err := collection.GetDocument(ctx, docID, DocUnmarshalAll)
4087 require.NoError(t, err)
4088 if !tc.useHLV {
4089 require.Nil(t, preResyncDoc.HLV)
4090 }
4091 _, _, err = collection.ResyncDocument(ctx, docID, realDocID(docID), false, []uint64{10})
4092 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

CasToStringFunction · 0.92
setupTestDBFunction · 0.85
realDocIDFunction · 0.85
UpdateSyncFunMethod · 0.80
ResyncDocumentMethod · 0.80
getDocWithXattrsMethod · 0.80
CloseMethod · 0.65
RunMethod · 0.65
PutMethod · 0.65
GetDocumentMethod · 0.65

Tested by

no test coverage detected