summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2021-11-28 00:34:25 +0100
committerTor Egge <Tor.Egge@online.no>2021-11-28 00:34:25 +0100
commit63f3315e2b3eef38d47bf29bee647d13386ec448 (patch)
tree770bc2b3c8427dad9ee92b6fb3227055e547eac8 /vespalib
parent4d30b12c7ee3f94231f9dd3a3ba9a0e5821f1295 (diff)
Avoid livelock when running sharded hash map unit test with valgrind.
Diffstat (limited to 'vespalib')
-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;