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

Function TestDeltaSyncWhenFromRevIsChannelRemoval

db/database_test.go:1363–1471  ·  view source on GitHub ↗

Test delta sync behavior when the fromRevision is a channel removal.

(t *testing.T)

Source from the content-addressed store, hash-verified

1361
1362// Test delta sync behavior when the fromRevision is a channel removal.
1363func TestDeltaSyncWhenFromRevIsChannelRemoval(t *testing.T) {
1364 if !base.IsEnterpriseEdition() {
1365 t.Skip("Delta sync only supported in EE")
1366 }
1367
1368 testCases := []struct {
1369 name string
1370 versionVector bool
1371 }{
1372 {
1373 name: "revTree test",
1374 versionVector: false,
1375 },
1376 {
1377 name: "versionVector test",
1378 versionVector: true,
1379 },
1380 }
1381 for _, testCase := range testCases {
1382 t.Run(testCase.name, func(t *testing.T) {
1383 db, ctx := SetupTestDBWithOptions(t, DatabaseContextOptions{DeltaSyncOptions: DeltaSyncOptions{Enabled: true, RevMaxAgeSeconds: 300}})
1384 defer db.Close(ctx)
1385 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
1386
1387 // Create the first revision of doc1.
1388 rev1Body := Body{
1389 "k1": "v1",
1390 "channels": []string{"ABC", "NBC"},
1391 }
1392 rev1ID, _, err := collection.Put(ctx, "doc1", rev1Body)
1393 require.NoError(t, err, "Error creating doc")
1394
1395 // Create the second revision of doc1 on channel ABC as removal from channel NBC.
1396 rev2Body := Body{
1397 "k2": "v2",
1398 "channels": []string{"ABC"},
1399 BodyRev: rev1ID,
1400 }
1401 rev2ID, docRev2, err := collection.Put(ctx, "doc1", rev2Body)
1402 require.NoError(t, err, "Error creating doc")
1403
1404 // Create the third revision of doc1 on channel ABC.
1405 rev3Body := Body{
1406 "k3": "v3",
1407 "channels": []string{"ABC"},
1408 BodyRev: rev2ID,
1409 }
1410 rev3ID, docRev3, err := collection.Put(ctx, "doc1", rev3Body)
1411 require.NoError(t, err, "Error creating doc")
1412 require.NotEmpty(t, rev3ID, "Error creating doc")
1413
1414 // Flush the revision cache and purge the old revision backup.
1415 db.FlushRevisionCacheForTest()
1416 if testCase.versionVector {
1417 cvStr := docRev2.HLV.GetCurrentVersionString()
1418 err = collection.PurgeOldRevisionJSON(ctx, "doc1", base.Crc32cHashString([]byte(cvStr)))
1419 require.NoError(t, err, "Error purging old revision JSON")
1420 } else {

Callers

nothing calls this directly

Calls 15

IsEnterpriseEditionFunction · 0.92
Crc32cHashStringFunction · 0.92
SetOfFunction · 0.92
HTTPErrorfFunction · 0.92
SetupTestDBWithOptionsFunction · 0.85
PurgeOldRevisionJSONMethod · 0.80
NewUserMethod · 0.80
InitDeltaSyncStatsMethod · 0.80

Tested by

no test coverage detected