summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp15
1 files changed, 15 insertions, 0 deletions
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 <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/datastore/unique_store_allocator.hpp>
+#include <thread>
#include <vespa/log/log.h>
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;