TestConcurrentPutAndGetOnRevCache: - Perform a Get with rev on the cache for a doc not in the cache - Concurrently perform a PUT on the cache with doc revision the same as the GET - Assert we get consistent cache with only 1 entry in lookup maps and the cache itself
(t *testing.T)
| 2026 | // - Concurrently perform a PUT on the cache with doc revision the same as the GET |
| 2027 | // - Assert we get consistent cache with only 1 entry in lookup maps and the cache itself |
| 2028 | func TestConcurrentPutAndGetOnRevCache(t *testing.T) { |
| 2029 | cacheHitCounter, cacheMissCounter, cacheNumItems, memoryBytesCounted, getDocumentCounter, getRevisionCounter := base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{} |
| 2030 | cacheOptions := &RevisionCacheOptions{ |
| 2031 | MaxItemCount: 10, |
| 2032 | MaxBytes: 0, |
| 2033 | } |
| 2034 | cache := NewLRURevisionCache(cacheOptions, CreateTestSingleBackingStoreMap(&testBackingStore{[]string{"test_doc"}, &getDocumentCounter, &getRevisionCounter}, testCollectionID), &cacheHitCounter, &cacheMissCounter, &cacheNumItems, &memoryBytesCounted) |
| 2035 | |
| 2036 | ctx := base.TestCtx(t) |
| 2037 | |
| 2038 | wg := sync.WaitGroup{} |
| 2039 | wg.Add(2) |
| 2040 | |
| 2041 | cv := Version{SourceID: "test", Value: 123} |
| 2042 | docRev := DocumentRevision{ |
| 2043 | DocID: "doc1", |
| 2044 | RevID: "1-abc", |
| 2045 | BodyBytes: []byte(`{"testing":true}`), |
| 2046 | Channels: base.SetOf("chan1"), |
| 2047 | History: Revisions{"start": 1}, |
| 2048 | CV: &cv, |
| 2049 | } |
| 2050 | |
| 2051 | go func() { |
| 2052 | _, err := cache.GetWithRev(ctx, "doc1", "1-abc", testCollectionID, RevCacheIncludeDelta) |
| 2053 | require.NoError(t, err) |
| 2054 | wg.Done() |
| 2055 | }() |
| 2056 | |
| 2057 | go func() { |
| 2058 | cache.Put(ctx, docRev, testCollectionID) |
| 2059 | wg.Done() |
| 2060 | }() |
| 2061 | |
| 2062 | wg.Wait() |
| 2063 | |
| 2064 | revElement := cache.cache[IDAndRev{RevID: "1-abc", DocID: "doc1"}].Value.(*revCacheValue) |
| 2065 | cvElement := cache.hlvCache[IDandCV{DocID: "doc1", Source: "test", Version: 123}].Value.(*revCacheValue) |
| 2066 | |
| 2067 | assert.LessOrEqual(t, cache.lruList.Len(), 2) |
| 2068 | assert.Equal(t, 1, len(cache.cache)) |
| 2069 | assert.Equal(t, 1, len(cache.hlvCache)) |
| 2070 | assert.Equal(t, revElement.revID, cvElement.revID) |
| 2071 | assert.Equal(t, revElement.id, cvElement.id) |
| 2072 | assert.Equal(t, revElement.cv.String(), cvElement.cv.String()) |
| 2073 | var revElem Body |
| 2074 | var cvElem Body |
| 2075 | err := base.JSONUnmarshal(revElement.bodyBytes, &revElem) |
| 2076 | require.NoError(t, err) |
| 2077 | err = base.JSONUnmarshal(cvElement.bodyBytes, &cvElem) |
| 2078 | require.NoError(t, err) |
| 2079 | assert.Equal(t, revElem["testing"].(bool), cvElem["testing"].(bool)) |
| 2080 | } |
| 2081 | |
| 2082 | func TestLoadActiveDocFromBucketRevCacheChurn(t *testing.T) { |
| 2083 | base.SkipImportTestsIfNotEnabled(t) |
nothing calls this directly
no test coverage detected