From 63f3315e2b3eef38d47bf29bee647d13386ec448 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Sun, 28 Nov 2021 00:34:25 +0100 Subject: Avoid livelock when running sharded hash map unit test with valgrind. --- .../datastore/sharded_hash_map/sharded_hash_map_test.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp b/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp index 799f2c79dd4..3cd3d00645c 100644 --- a/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp +++ b/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp @@ -11,6 +11,7 @@ #include #include +#include #include LOG_SETUP("vespalib_datastore_shared_hash_test"); @@ -24,6 +25,18 @@ using MyHashMap = vespalib::datastore::ShardedHashMap; using GenerationHandler = vespalib::GenerationHandler; using vespalib::makeLambdaTask; +namespace { + +void consider_yield(uint32_t i) +{ + if ((i % 1000) == 0) { + // Need to yield sometimes to avoid livelock when running unit test with valgrind + std::this_thread::yield(); + } +} + +} + struct DataStoreShardedHashTest : public ::testing::Test { GenerationHandler _generationHandler; @@ -142,6 +155,7 @@ DataStoreShardedHashTest::read_work(uint32_t cnt) EXPECT_EQ(key, wrapped_entry.value()); ++found; } + consider_yield(i); } _done_read_work += i; _found_count += found; @@ -168,6 +182,7 @@ DataStoreShardedHashTest::write_work(uint32_t cnt) remove(key); } commit(); + consider_yield(i); } _done_write_work += cnt; _stop_read = 1; -- cgit v1.2.3