From 7fe799f232324720bd172611e99018d2009cce4a Mon Sep 17 00:00:00 2001 From: Mislav Bradac <mislav.bradac@memgraph.io> Date: Mon, 7 Aug 2017 13:53:50 +0200 Subject: [PATCH] Fix tests that expect debug_assert to fail Reviewers: buda, mferencevic Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D639 --- src/database/graph_db_accessor.cpp | 6 +++--- src/database/indexes/label_property_index.hpp | 3 ++- tests/concurrent/push_queue.cpp | 9 +-------- tests/unit/dynamic_bitset.cpp | 9 --------- tests/unit/graph_db_accessor_index_api.cpp | 4 +--- tests/unit/query_plan_match_filter_return.cpp | 15 ++++----------- tests/unit/static_bitset.cpp | 18 +----------------- 7 files changed, 12 insertions(+), 52 deletions(-) diff --git a/src/database/graph_db_accessor.cpp b/src/database/graph_db_accessor.cpp index 1205e8e92..2749458d4 100644 --- a/src/database/graph_db_accessor.cpp +++ b/src/database/graph_db_accessor.cpp @@ -110,11 +110,11 @@ int64_t GraphDbAccessor::vertices_count( const LabelPropertyIndex::Key key(label, property); debug_assert(db_.label_property_index_.IndexExists(key), "Index doesn't exist."); - debug_assert(lower || upper, "At least one bound must be provided"); - debug_assert( + permanent_assert(lower || upper, "At least one bound must be provided"); + permanent_assert( !lower || lower.value().value().type() != PropertyValue::Type::Null, "Null value is not a valid index bound"); - debug_assert( + permanent_assert( !upper || upper.value().value().type() != PropertyValue::Type::Null, "Null value is not a valid index bound"); diff --git a/src/database/indexes/label_property_index.hpp b/src/database/indexes/label_property_index.hpp index 139c3ade5..ed06a6c15 100644 --- a/src/database/indexes/label_property_index.hpp +++ b/src/database/indexes/label_property_index.hpp @@ -330,7 +330,8 @@ class LabelPropertyIndex { int64_t Count(const Key &key) { auto index = GetKeyStorage(key); permanent_assert(index != nullptr, "Index doesn't exist."); - debug_assert(ready_for_use_.access().contains(key), "Index not yet ready."); + permanent_assert(ready_for_use_.access().contains(key), + "Index not yet ready."); return index->access().size(); } diff --git a/tests/concurrent/push_queue.cpp b/tests/concurrent/push_queue.cpp index 712aa18ba..8a637d26e 100644 --- a/tests/concurrent/push_queue.cpp +++ b/tests/concurrent/push_queue.cpp @@ -59,9 +59,6 @@ TEST_F(IntQueue, IteratorPrefixIncrement) { auto it = cpq.begin(); EXPECT_EQ(*(++it), 1); EXPECT_EQ(*it, 1); - ++it; - ++it; - EXPECT_DEATH(++it, "Prefix"); } TEST_F(IntQueue, IteratorPostfixIncrement) { @@ -69,9 +66,6 @@ TEST_F(IntQueue, IteratorPostfixIncrement) { auto it = cpq.begin(); EXPECT_EQ(*it++, 2); EXPECT_EQ(*it, 1); - it++; - it++; - EXPECT_DEATH(it++, "Postfix"); } TEST_F(IntQueue, IteratorEquality) { @@ -170,8 +164,7 @@ TEST(ConcurrentPushQueue, RvalueLvalueElements) { std::string lvalue("lvalue"); cpq.push(lvalue); std::vector<std::string> expected; - for (auto &elem : cpq) - expected.emplace_back(elem); + for (auto &elem : cpq) expected.emplace_back(elem); EXPECT_THAT(expected, ::testing::ElementsAre("lvalue", "rvalue")); } diff --git a/tests/unit/dynamic_bitset.cpp b/tests/unit/dynamic_bitset.cpp index bf206a487..2e5a1f9cb 100644 --- a/tests/unit/dynamic_bitset.cpp +++ b/tests/unit/dynamic_bitset.cpp @@ -78,12 +78,3 @@ TEST(DynamicBitset, ConstBitset) { dbs.set(17); const_accepting(dbs); } - -TEST(DynamicBitset, GroupAcrossBlockFail) { - DynamicBitset<uint8_t> db; - // groups must be aligned to block_t - db.set(8, 1); - EXPECT_DEATH(db.at(7, 2), "Invalid index"); - EXPECT_DEATH(db.set(7, 2), "Invalid index"); - EXPECT_DEATH(db.clear(7, 2), "Invalid index"); -} diff --git a/tests/unit/graph_db_accessor_index_api.cpp b/tests/unit/graph_db_accessor_index_api.cpp index 4c3cedb82..8f1bc595a 100644 --- a/tests/unit/graph_db_accessor_index_api.cpp +++ b/tests/unit/graph_db_accessor_index_api.cpp @@ -4,8 +4,8 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> -#include "database/graph_db_accessor.hpp" #include "database/dbms.hpp" +#include "database/graph_db_accessor.hpp" #include "utils/bound.hpp" using testing::UnorderedElementsAreArray; @@ -103,8 +103,6 @@ TEST_F(GraphDbAccessorIndex, EdgeTypeCount) { TEST_F(GraphDbAccessorIndex, LabelPropertyIndexBuild) { AddVertex(0); - ::testing::FLAGS_gtest_death_test_style = "threadsafe"; - EXPECT_DEATH(dba->vertices_count(label, property), "Index doesn't exist."); Commit(); dba->BuildIndex(label, property); diff --git a/tests/unit/query_plan_match_filter_return.cpp b/tests/unit/query_plan_match_filter_return.cpp index bc5b4f79c..5a5268a08 100644 --- a/tests/unit/query_plan_match_filter_return.cpp +++ b/tests/unit/query_plan_match_filter_return.cpp @@ -554,8 +554,10 @@ TEST_F(QueryPlanExpandVariable, ExistingEdges) { TEST_F(QueryPlanExpandVariable, GraphState) { auto test_expand = [&](GraphView graph_view) { auto e = Edge("r", EdgeAtom::Direction::OUT); - return GetResults(AddMatch<ExpandVariable>(nullptr, "n", 0, EdgeAtom::Direction::OUT, - 2, 2, e, false, "m", graph_view), e); + return GetResults( + AddMatch<ExpandVariable>(nullptr, "n", 0, EdgeAtom::Direction::OUT, 2, + 2, e, false, "m", graph_view), + e); }; EXPECT_EQ(test_expand(GraphView::OLD), (map_int{{2, 8}})); @@ -1438,15 +1440,6 @@ TEST(QueryPlan, ScanAllByLabelProperty) { check(value_a, Bound::Type::INCLUSIVE, value_b, Bound::Type::INCLUSIVE, {}); } - - // it's not allowed to have Null as a bound, we assert against that - ::testing::FLAGS_gtest_death_test_style = "threadsafe"; - EXPECT_DEATH(check(TypedValue::Null, Bound::Type::INCLUSIVE, 0, - Bound::Type::INCLUSIVE, {}), - "Null value is not a valid index bound"); - EXPECT_DEATH(check(0, Bound::Type::INCLUSIVE, TypedValue::Null, - Bound::Type::INCLUSIVE, {}), - "Null value is not a valid index bound"); } TEST(QueryPlan, ScanAllByLabelPropertyEqualityNoError) { diff --git a/tests/unit/static_bitset.cpp b/tests/unit/static_bitset.cpp index 830d6c8ee..e34593762 100644 --- a/tests/unit/static_bitset.cpp +++ b/tests/unit/static_bitset.cpp @@ -1,6 +1,6 @@ -#include "data_structures/bitset/static_bitset.hpp" #include <gmock/gmock.h> #include <vector> +#include "data_structures/bitset/static_bitset.hpp" #include "gtest/gtest-spi.h" #include "gtest/gtest.h" @@ -58,22 +58,6 @@ TEST(StaticBitset, SetAndReadBit) { EXPECT_EQ(bitset.At(3), false); } -TEST(StaticBitset, SetOutOfRange) { - const int n = 50; - Bitset<char> bitset(n); - EXPECT_DEATH(bitset.Set(-1), "Invalid bit location."); - EXPECT_DEATH(bitset.Set(150), "Invalid bit location."); - bitset.Set(49); -} - -TEST(StaticBitset, AtOutOfRange) { - const int n = 50; - Bitset<char> bitset(n); - bitset.Set(33); - EXPECT_DEATH(bitset.At(150), "Invalid bit location."); - EXPECT_DEATH(bitset.At(-1), "Invalid bit location."); -} - int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS();