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

Function TestRevisionPruningLoop

db/revtree_test.go:1002–1071  ·  view source on GitHub ↗

TODO: add test for two tombstone branches getting pruned at once Repro case for https://github.com/couchbase/sync_gateway/issues/2847

(t *testing.T)

Source from the content-addressed store, hash-verified

1000
1001// Repro case for https://github.com/couchbase/sync_gateway/issues/2847
1002func TestRevisionPruningLoop(t *testing.T) {
1003
1004 revsLimit := uint32(5)
1005 revBody := []byte(`{"foo":"bar"}`)
1006 nonTombstone := false
1007 tombstone := true
1008
1009 // create rev tree with a root entry
1010 revTree := RevTree{}
1011 err := addAndGet(t, revTree, "1-foo", "", nonTombstone)
1012 assert.NoError(t, err, "Error adding revision 1-foo to tree")
1013
1014 // Add several entries (2-foo to 5-foo)
1015 for generation := 2; generation <= 5; generation++ {
1016 revID := fmt.Sprintf("%d-foo", generation)
1017 parentRevID := fmt.Sprintf("%d-foo", generation-1)
1018 err := addAndGet(t, revTree, revID, parentRevID, nonTombstone)
1019 assert.NoError(t, err, fmt.Sprintf("Error adding revision %s to tree", revID))
1020 }
1021
1022 // Add tombstone children of 3-foo and 4-foo
1023
1024 err = addAndGet(t, revTree, "4-bar", "3-foo", nonTombstone)
1025 require.NoError(t, err)
1026 err = addAndGet(t, revTree, "5-bar", "4-bar", tombstone)
1027 assert.NoError(t, err, "Error adding tombstone 4-bar to tree")
1028
1029 /*
1030 // Add a second branch as a child of 2-foo.
1031 err = addAndGet(revTree, "3-bar", "2-foo", nonTombstone)
1032 assert.NoError(t, err, "Error adding revision 3-bar to tree")
1033
1034 // Tombstone the second branch
1035 err = addAndGet(revTree, "4-bar", "3-bar", tombstone)
1036 assert.NoError(t, err, "Error adding tombstone 4-bar to tree")
1037 */
1038
1039 // Add a another tombstoned branch as a child of 5-foo. This will ensure that 2-foo doesn't get pruned
1040 // until the first tombstone branch is deleted.
1041 /*
1042 err = addAndGet(revTree, "6-bar2", "5-foo", tombstone)
1043 assert.NoError(t, err, "Error adding tombstone 6-bar2 to tree")
1044 */
1045
1046 log.Printf("Tree before adding to main branch: [[%s]]", revTree.RenderGraphvizDot())
1047
1048 // Keep adding to the main branch without pruning. Simulates old pruning algorithm,
1049 // which maintained rev history due to tombstone branch
1050 ctx := base.TestCtx(t)
1051 for generation := 6; generation <= 15; generation++ {
1052 revID := fmt.Sprintf("%d-foo", generation)
1053 parentRevID := fmt.Sprintf("%d-foo", generation-1)
1054 _, err := addPruneAndGet(ctx, revTree, revID, parentRevID, revBody, revsLimit, nonTombstone)
1055 assert.NoError(t, err, fmt.Sprintf("Error adding revision %s to tree", revID))
1056
1057 keepAliveRevID := fmt.Sprintf("%d-keep", generation)
1058 _, err = addPruneAndGet(ctx, revTree, keepAliveRevID, parentRevID, revBody, revsLimit, tombstone)
1059 assert.NoError(t, err, fmt.Sprintf("Error adding revision %s to tree", revID))

Callers

nothing calls this directly

Calls 6

RenderGraphvizDotMethod · 0.95
MarshalJSONMethod · 0.95
UnmarshalJSONMethod · 0.95
TestCtxFunction · 0.92
addAndGetFunction · 0.85
addPruneAndGetFunction · 0.85

Tested by

no test coverage detected