From 4064a85ccf98cb56a3572fc4c57dcf1cdb21278b Mon Sep 17 00:00:00 2001 From: Johannes Kalmbach Date: Thu, 12 Dec 2024 16:20:59 +0100 Subject: [PATCH] A small improvement for the tests. Signed-off-by: Johannes Kalmbach --- test/ConcurrentCacheTest.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/ConcurrentCacheTest.cpp b/test/ConcurrentCacheTest.cpp index 3346868c48..9dbfbde509 100644 --- a/test/ConcurrentCacheTest.cpp +++ b/test/ConcurrentCacheTest.cpp @@ -533,30 +533,36 @@ TEST(ConcurrentCache, testTryInsertIfNotPresentDoesWorkCorrectly) { TEST(ConcurrentCache, computeButDontStore) { SimpleConcurrentLruCache cache{}; + + // The last argument of `computeOnce...`: For the sake of this test, all + // results are suitable for the cache. Note: In the `computeButDontStore` + // function this argument is ignored, because the results are never stored in + // the cache. + auto alwaysSuitable = [](auto&&) { return true; }; // Store the element in the cache. cache.computeOnce( - 42, []() { return "42"; }, false, [](auto&&) { return true; }); + 42, []() { return "42"; }, false, alwaysSuitable); // The result is read from the cache, so we get "42", not "blubb". auto res = cache.computeButDontStore( - 42, []() { return "blubb"; }, false, [](auto&&) { return true; }); + 42, []() { return "blubb"; }, false, alwaysSuitable); EXPECT_EQ(*res._resultPointer, "42"); // The same with `onlyReadFromCache` == true; res = cache.computeButDontStore( - 42, []() { return "blubb"; }, true, [](auto&&) { return true; }); + 42, []() { return "blubb"; }, true, alwaysSuitable); EXPECT_EQ(*res._resultPointer, "42"); cache.clearAll(); // Compute, but don't store. res = cache.computeButDontStore( - 42, []() { return "blubb"; }, false, [](auto&&) { return true; }); + 42, []() { return "blubb"; }, false, alwaysSuitable); EXPECT_EQ(*res._resultPointer, "blubb"); // Nothing is stored in the cache, so we cannot read it. EXPECT_FALSE(cache.getIfContained(42).has_value()); res = cache.computeButDontStore( - 42, []() { return "blubb"; }, true, [](auto&&) { return true; }); + 42, []() { return "blubb"; }, true, alwaysSuitable); EXPECT_EQ(res._resultPointer, nullptr); }