TestConcurrentLoadByCVAndRevOnCache: - Create cache - Now perform two concurrent Gets, one by CV and one by revid on a document that doesn't exist in the cache - This will trigger two concurrent loads from bucket in the CV code path and revid code path - In doing so we will have two processes trying
(t *testing.T)
| 1942 | // element |
| 1943 | // - Grab the single element in the list and assert that both maps point to that element in the cache list |
| 1944 | func TestConcurrentLoadByCVAndRevOnCache(t *testing.T) { |
| 1945 | cacheHitCounter, cacheMissCounter, cacheNumItems, memoryBytesCounted, getDocumentCounter, getRevisionCounter := base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{} |
| 1946 | cacheOptions := &RevisionCacheOptions{ |
| 1947 | MaxItemCount: 10, |
| 1948 | MaxBytes: 0, |
| 1949 | } |
| 1950 | cache := NewLRURevisionCache(cacheOptions, CreateTestSingleBackingStoreMap(&testBackingStore{[]string{"test_doc"}, &getDocumentCounter, &getRevisionCounter}, testCollectionID), &cacheHitCounter, &cacheMissCounter, &cacheNumItems, &memoryBytesCounted) |
| 1951 | |
| 1952 | ctx := base.TestCtx(t) |
| 1953 | |
| 1954 | wg := sync.WaitGroup{} |
| 1955 | wg.Add(2) |
| 1956 | |
| 1957 | cv := Version{SourceID: "test", Value: 123} |
| 1958 | go func() { |
| 1959 | _, err := cache.GetWithRev(ctx, "doc1", "1-abc", testCollectionID, RevCacheIncludeDelta) |
| 1960 | require.NoError(t, err) |
| 1961 | wg.Done() |
| 1962 | }() |
| 1963 | |
| 1964 | go func() { |
| 1965 | _, err := cache.GetWithCV(ctx, "doc1", &cv, testCollectionID, RevCacheIncludeDelta, false) |
| 1966 | require.NoError(t, err) |
| 1967 | wg.Done() |
| 1968 | }() |
| 1969 | |
| 1970 | wg.Wait() |
| 1971 | |
| 1972 | revElement := cache.cache[IDAndRev{RevID: "1-abc", DocID: "doc1"}].Value.(*revCacheValue) |
| 1973 | cvElement := cache.hlvCache[IDandCV{DocID: "doc1", Source: "test", Version: 123}].Value.(*revCacheValue) |
| 1974 | // we may have concurrent loads that lead to the same doc being loaded into two |
| 1975 | // rev cache items but only one reference to one or the other in the maps |
| 1976 | // ┌──────────┐ ┌──────────┐ |
| 1977 | // │ │ │ │ |
| 1978 | // │ Doc1 │ │ Doc1 │ |
| 1979 | // │ │ │ │ |
| 1980 | // └──────────┘ └──────────┘ |
| 1981 | // ▲ ▲ |
| 1982 | // │ │ |
| 1983 | // │ │ |
| 1984 | // ┌──────┐ ┌──────┐ |
| 1985 | // │ HLV │ │ REV │ |
| 1986 | // │ MAP │ │ MAP │ |
| 1987 | // └──────┘ └──────┘ |
| 1988 | |
| 1989 | assert.LessOrEqual(t, cache.lruList.Len(), 2) |
| 1990 | assert.Equal(t, 1, len(cache.cache)) |
| 1991 | assert.Equal(t, 1, len(cache.hlvCache)) |
| 1992 | assert.Equal(t, revElement.revID, cvElement.revID) |
| 1993 | assert.Equal(t, revElement.id, cvElement.id) |
| 1994 | assert.Equal(t, revElement.cv.String(), cvElement.cv.String()) |
| 1995 | require.JSONEq(t, string(revElement.bodyBytes), string(cvElement.bodyBytes)) |
| 1996 | } |
| 1997 | |
| 1998 | // TestGetActive: |
| 1999 | // - Create db, create a doc on the db |
nothing calls this directly
no test coverage detected