Skip to content

Commit

Permalink
Merge pull request #32703 from vespa-engine/toregge/rewrite-searchcor…
Browse files Browse the repository at this point in the history
…e-feed-debugger-unit-test-to-gtest

Rewrite searchcore feed debugger unit test to gtest.
  • Loading branch information
geirst authored Oct 29, 2024
2 parents 4594c80 + 96ba590 commit 86cb378
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion searchcore/src/tests/proton/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
vespa_add_executable(searchcore_proton_server_vespa_test_app TEST
SOURCES
vespa_testrunner.cpp
feeddebugger_test.cpp
feedstates_test.cpp
health_adapter_test.cpp
memory_flush_config_updater_test.cpp
Expand All @@ -20,6 +19,7 @@ vespa_add_executable(searchcore_proton_server_gtest_test_app TEST
SOURCES
gtest_runner.cpp
documentretriever_test.cpp
feeddebugger_test.cpp
DEPENDS
searchcore_server
GTest::gtest
Expand Down
38 changes: 18 additions & 20 deletions searchcore/src/tests/proton/server/feeddebugger_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

#include <vespa/document/base/documentid.h>
#include <vespa/searchcore/proton/common/feeddebugger.h>
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/testkit/test_master.hpp>
#include <vespa/vespalib/gtest/gtest.h>

using document::DocumentId;
using std::string;
Expand Down Expand Up @@ -37,42 +36,41 @@ class EnvSaver {
}
};

TEST("require that when environment variable is not set, debugging is off") {
}

TEST(FeedDebuggerTest, require_that_when_environment_variable_is_not_set_debugging_is_off)
{
EnvSaver save_lid_env(lid_env_name);
EnvSaver save_docid_env(docid_env_name);
FeedDebugger debugger;
EXPECT_FALSE(debugger.isDebugging());
}

TEST("require that setting an environment variable turns on lid-specific debugging.") {
TEST(FeedDebuggerTest, require_that_setting_an_environment_variable_turns_on_lid_specific_debugging)
{
EnvSaver save_lid_env(lid_env_name);
EnvSaver save_docid_env(docid_env_name);
setenv(lid_env_name, "1,3,5", true);

FeedDebugger debugger;
EXPECT_TRUE(debugger.isDebugging());
EXPECT_EQUAL(ns_log::Logger::info, debugger.getDebugLevel(1, 0));
EXPECT_EQUAL(ns_log::Logger::spam, debugger.getDebugLevel(2, 0));
EXPECT_EQUAL(ns_log::Logger::info, debugger.getDebugLevel(3, 0));
EXPECT_EQUAL(ns_log::Logger::spam, debugger.getDebugLevel(4, 0));
EXPECT_EQUAL(ns_log::Logger::info, debugger.getDebugLevel(5, 0));
EXPECT_EQ(ns_log::Logger::info, debugger.getDebugLevel(1, 0));
EXPECT_EQ(ns_log::Logger::spam, debugger.getDebugLevel(2, 0));
EXPECT_EQ(ns_log::Logger::info, debugger.getDebugLevel(3, 0));
EXPECT_EQ(ns_log::Logger::spam, debugger.getDebugLevel(4, 0));
EXPECT_EQ(ns_log::Logger::info, debugger.getDebugLevel(5, 0));
}

TEST("require that setting an environment variable turns on docid-specific debugging.") {
TEST(FeedDebuggerTest, require_that_setting_an_environment_variable_turns_on_docid_specific_debugging)
{
EnvSaver save_lid_env(lid_env_name);
EnvSaver save_docid_env(docid_env_name);
setenv(docid_env_name, "id:ns:type::test:foo,id:ns:type::test:bar,id:ns:type::test:baz", true);

FeedDebugger debugger;
EXPECT_TRUE(debugger.isDebugging());
EXPECT_EQUAL(ns_log::Logger::info,
debugger.getDebugLevel(1, DocumentId("id:ns:type::test:foo")));
EXPECT_EQUAL(ns_log::Logger::info,
debugger.getDebugLevel(1, DocumentId("id:ns:type::test:bar")));
EXPECT_EQUAL(ns_log::Logger::info,
debugger.getDebugLevel(1, DocumentId("id:ns:type::test:baz")));
EXPECT_EQUAL(ns_log::Logger::spam,
debugger.getDebugLevel(1, DocumentId("id:ns:type::test:qux")));
EXPECT_EQ(ns_log::Logger::info, debugger.getDebugLevel(1, DocumentId("id:ns:type::test:foo")));
EXPECT_EQ(ns_log::Logger::info, debugger.getDebugLevel(1, DocumentId("id:ns:type::test:bar")));
EXPECT_EQ(ns_log::Logger::info, debugger.getDebugLevel(1, DocumentId("id:ns:type::test:baz")));
EXPECT_EQ(ns_log::Logger::spam, debugger.getDebugLevel(1, DocumentId("id:ns:type::test:qux")));
}

} // namespace

0 comments on commit 86cb378

Please sign in to comment.