diff --git a/cachelib/allocator/nvmcache/tests/NvmCacheTests.cpp b/cachelib/allocator/nvmcache/tests/NvmCacheTests.cpp index 6ba940a45..774d491b7 100644 --- a/cachelib/allocator/nvmcache/tests/NvmCacheTests.cpp +++ b/cachelib/allocator/nvmcache/tests/NvmCacheTests.cpp @@ -215,11 +215,11 @@ TEST_F(NvmCacheTest, EvictToNvmGet) { const auto nEvictions = this->evictionCount() - evictBefore; ASSERT_LT(0, nEvictions); - // read from ram cache first so that we will not cause evictions + // Read from ram cache first so that we will not cause evictions // to navy for items that are still in ram-cache until we start - // reading items from navy + // reading items from navy. for (unsigned int i = nKeys + 100; i-- > 0;) { - unsigned int index = i - 1; + unsigned int index = i; auto key = folly::sformat("key{}", index); auto hdl = this->fetch(key, false /* ramOnly */); hdl.wait(); @@ -248,6 +248,10 @@ TEST_F(NvmCacheTest, EvictToNvmGet) { } } + // Flush to ensure all async navy callbacks (including GetCtx destruction + // which decrements handle counts) have fully completed. + nvm.flushNvmCache(); + // Reads are done. We should be at "0" active handle count across all threads. ASSERT_EQ(0, nvm.getNumActiveHandles()); ASSERT_EQ(0, nvm.getHandleCountForThread());