aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahoo-inc.com>2017-03-09 14:17:32 +0000
committerGeir Storli <geirst@yahoo-inc.com>2017-03-09 14:17:32 +0000
commit25014e1d214f41fe4de3e2d42ef6a92bf4afa6f8 (patch)
treeb02cc71899dfd6377e89c1791f96d57938eea57d /searchlib
parent853cff57ce2ff6f1760bfe363118d24f3cd5fcb4 (diff)
Improve testing of acquireEnumGuard() by checking that guard is taken on underlying target attribute.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp b/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
index 62b337bfc59..108def1b829 100644
--- a/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
+++ b/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
@@ -12,10 +12,11 @@
#include <vespa/searchlib/test/mock_gid_to_lid_mapping.h>
#include <vespa/searchcommon/attribute/attributecontent.h>
#include <vespa/vespalib/testkit/testapp.h>
-#include <memory>
+#include <algorithm>
#include <map>
+#include <memory>
+#include <thread>
#include <vector>
-#include <algorithm>
namespace search {
namespace attribute {
@@ -223,6 +224,13 @@ void reset_with_wset_value_reference_mappings(
f.reset_with_wset_value_reference_mappings<AttrVecType, WeightedValueType>(type, mappings);
}
+bool has_active_enum_guards(AttributeVector &attr) {
+ bool result;
+ std::thread thread([&result, &attr]() { result = attr.hasActiveEnumGuards(); });
+ thread.join();
+ return result;
+}
+
TEST_F("Accessors return expected attributes", Fixture) {
EXPECT_EQUAL(f.imported_attr->getReferenceAttribute().get(),
f.reference_attr.get());
@@ -285,11 +293,6 @@ TEST_F("acquireEnumGuard() acquires enum guard on target and regular guard on re
add_n_docs_with_undefined_values(*f.target_attr, 2);
{
auto guard = f.imported_attr->acquireEnumGuard();
- // We can add docs, but not mutate enum values. That would deadlock the test, as the
- // attribute enum guard already holds a shared lock. Could test the mutex itself to
- // verify that it is indeed locked, but that's a private member in AttributeVector,
- // so would be Very Dirty(tm).
- // TODO find a robust way to test this.
add_n_docs_with_undefined_values(*f.target_attr, 1);
add_n_docs_with_undefined_values(*f.reference_attr, 1);
@@ -298,12 +301,14 @@ TEST_F("acquireEnumGuard() acquires enum guard on target and regular guard on re
EXPECT_EQUAL(3u, f.target_attr->getFirstUsedGeneration());
EXPECT_EQUAL(1u, f.reference_attr->getFirstUsedGeneration());
+ EXPECT_TRUE(has_active_enum_guards(*f.target_attr));
}
// Force a generation handler update
add_n_docs_with_undefined_values(*f.reference_attr, 1);
add_n_docs_with_undefined_values(*f.target_attr, 1);
EXPECT_EQUAL(7u, f.target_attr->getFirstUsedGeneration());
EXPECT_EQUAL(3u, f.reference_attr->getFirstUsedGeneration());
+ EXPECT_FALSE(has_active_enum_guards(*f.target_attr));
}
TEST_F("Single-valued integer attribute values can be retrieved via reference", Fixture) {