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

Function TestRepairUnorderedRecentSequences

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

Source from the content-addressed store, hash-verified

3638}
3639
3640func TestRepairUnorderedRecentSequences(t *testing.T) {
3641 if base.TestUseXattrs() {
3642 t.Skip("xattr=false only - test modifies doc _sync property")
3643 }
3644
3645 var db *Database
3646 var body Body
3647 var revid string
3648 var ctx context.Context
3649
3650 db, ctx = setupTestDB(t)
3651 defer db.Close(ctx)
3652 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
3653
3654 err := json.Unmarshal([]byte(`{"prop": "value"}`), &body)
3655 require.NoError(t, err)
3656
3657 // Create a doc
3658 revid, _, err = collection.Put(ctx, "doc1", body)
3659 require.NoError(t, err)
3660
3661 // Update the doc a few times to populate recent sequences
3662 for i := 0; i < 10; i++ {
3663 updateBody := make(map[string]interface{})
3664 updateBody["prop"] = i
3665 updateBody["_rev"] = revid
3666 revid, _, err = collection.Put(ctx, "doc1", updateBody)
3667 require.NoError(t, err)
3668 }
3669
3670 syncData, err := collection.GetDocSyncData(ctx, "doc1")
3671 require.NoError(t, err)
3672 assert.True(t, sort.IsSorted(base.SortedUint64Slice(syncData.RecentSequences)))
3673
3674 // Update document directly in the bucket to scramble recent sequences
3675 var rawBody Body
3676 _, err = collection.dataStore.Get("doc1", &rawBody)
3677 require.NoError(t, err)
3678 rawSyncData, ok := rawBody["_sync"].(map[string]interface{})
3679 require.True(t, ok)
3680 rawSyncData["recent_sequences"] = []uint64{3, 5, 9, 11, 1, 2, 4, 8, 7, 10, 5}
3681 assert.NoError(t, collection.dataStore.Set("doc1", 0, nil, rawBody))
3682
3683 // Validate non-ordered
3684 var rawBodyCheck Body
3685 _, err = collection.dataStore.Get("doc1", &rawBodyCheck)
3686 require.NoError(t, err)
3687 log.Printf("raw body check %v", rawBodyCheck)
3688 rawSyncDataCheck, ok := rawBody["_sync"].(map[string]interface{})
3689 require.True(t, ok)
3690 recentSequences, ok := rawSyncDataCheck["recent_sequences"].([]uint64)
3691 require.True(t, ok)
3692 assert.False(t, sort.IsSorted(base.SortedUint64Slice(recentSequences)))
3693
3694 // Update the doc again. expect sequences to now be ordered
3695 updateBody := make(map[string]interface{})
3696 updateBody["prop"] = 12
3697 updateBody["_rev"] = revid

Callers

nothing calls this directly

Calls 10

TestUseXattrsFunction · 0.92
SortedUint64SliceTypeAlias · 0.92
setupTestDBFunction · 0.85
GetDocSyncDataMethod · 0.80
CloseMethod · 0.65
PutMethod · 0.65
UnmarshalMethod · 0.45
GetMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected