(t *testing.T)
| 3638 | } |
| 3639 | |
| 3640 | func 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 |
nothing calls this directly
no test coverage detected