From: Michael Wallner Date: Tue, 15 Sep 2020 07:00:25 +0000 (+0200) Subject: testing: consolidate X-Git-Tag: 1.1.0-beta1~236^2~68 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=cebfad29f9703f768594b729c20ea0568765d52b;p=awesomized%2Flibmemcached testing: consolidate --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e13c1fd4..7b76f688 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,11 +40,7 @@ if(NOT BUILD_DOCSONLY) add_subdirectory(include) add_subdirectory(src) add_subdirectory(support) - - if(BUILD_TESTING) - add_subdirectory(testing) - add_subdirectory(tests) - endif() + add_subdirectory(testing) # keep last configure_file(src/mem_config.h.in ${AUTOHEADER_FILE} @ONLY) diff --git a/TODO b/TODO index 64ad32e4..622fed71 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,9 @@ +- Clients (src/bin): + - consolidate CLI + - convert to proper C++ where applicable + +## Legacy: + - Write a shell application (?) - Fix version in command line tools - Write (more) test cases for all command line tools (!!!) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f508ec04..3eaa0219 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,7 +4,3 @@ add_subdirectory(libhashkit) add_subdirectory(libmemcached) add_subdirectory(libmemcachedutil) add_subdirectory(libmemcachedprotocol) - -if(BUILD_TESTING) - add_subdirectory(libtest) -endif() diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 146e6231..b7de98fe 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -1,42 +1,51 @@ +if(NOT BUILD_TESTING) + return() +endif() file(GLOB_RECURSE TESTING_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) set(TESTING_ROOT ${CMAKE_CURRENT_BINARY_DIR}) +set_source_files_properties(main.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) configure_file(conf.h.in conf.h @ONLY) -add_executable(catch_main ${TESTING_SRC}) -set_target_properties(catch_main PROPERTIES CXX_STANDARD 17) -target_include_directories(catch_main PRIVATE +add_executable(runtests ${TESTING_SRC}) +set_target_properties(runtests PROPERTIES CXX_STANDARD 17) +target_include_directories(runtests PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src) -target_link_libraries(catch_main PRIVATE libhashkit libmemcached libmemcachedutil) -add_dependencies(catch_main ${CLIENTS}) +target_link_libraries(runtests PRIVATE libhashkit libmemcached libmemcachedutil) +add_dependencies(runtests ${CLIENTS}) -add_test("lib/Server" catch_main "lib/Server") -add_test("lib/Cluster" catch_main "lib/Cluster") +macro(add_test TEST_CASE) + _add_test(${TEST_CASE} runtests ${TEST_CASE}) +endmacro() -add_test("hashkit" catch_main "hashkit") +add_test("lib/Server") +add_test("lib/Cluster") -add_test("memcached_append" catch_main "memcached_append") -add_test("memcached_basic" catch_main "memcached_basic") -add_test("memcached_callbacks" catch_main "memcached_callbacks") -add_test("memcached_cas" catch_main "memcached_cas") -add_test("memcached_dump" catch_main "memcached_dump") -add_test("memcached_encoding_key" catch_main "memcached_encoding_key") -add_test("memcached_exist" catch_main "memcached_exist") -add_test("memcached_generate_hash" catch_main "memcached_generate_hash") -add_test("memcached_haldenbrand_nblock_tcp_ndelay" catch_main "memcached_haldenbrand_nblock_tcp_ndelay") -add_test("memcached_inc_dec" catch_main "memcached_inc_dec") -add_test("memcached_ketama_compat" catch_main "memcached_ketama_compat") -add_test("memcached_noreply" catch_main "memcached_noreply") -add_test("memcached_prepend" catch_main "memcached_prepend") -add_test("memcached_regression_binary_block_add" catch_main "memcached_regression_binary_block_add") -add_test("memcached_servers" catch_main "memcached_servers") -add_test("memcached_simple" catch_main "memcached_simple") -add_test("memcached_util" catch_main "memcached_util") +add_test("hashkit") -add_test("memcat" catch_main "memcat") -add_test("memcp" catch_main "memcp") -add_test("memdump" catch_main "memdump") -add_test("memerror" catch_main "memerror") -add_test("memexist" catch_main "memexist") +add_test("memcached_append") +add_test("memcached_basic") +add_test("memcached_callbacks") +add_test("memcached_cas") +add_test("memcached_dump") +add_test("memcached_encoding_key") +add_test("memcached_exist") +add_test("memcached_generate_hash") +add_test("memcached_haldenbrand_nblock_tcp_ndelay") +add_test("memcached_inc_dec") +add_test("memcached_ketama_compat") +add_test("memcached_noreply") +add_test("memcached_prepend") +add_test("memcached_regression_binary_block_add") +add_test("memcached_servers") +add_test("memcached_simple") +add_test("memcached_util") + +add_test("memcat") +add_test("memcp") +add_test("memdump") +add_test("memerror") +add_test("memexist") +add_test("memflush") diff --git a/testing/tests/bin/memcat.cpp b/testing/tests/bin/memcat.cpp index e09bf28e..9a787f81 100644 --- a/testing/tests/bin/memcat.cpp +++ b/testing/tests/bin/memcat.cpp @@ -28,7 +28,7 @@ TEST_CASE("memcat") { } SECTION("with server") { - Server server{"memcached"}; + Server server{"memcached", {"-p", random_port_string}}; MemcachedPtr memc; LoneReturnMatcher test{*memc}; diff --git a/testing/tests/bin/memcp.cpp b/testing/tests/bin/memcp.cpp index 6c69a502..0ba1af18 100644 --- a/testing/tests/bin/memcp.cpp +++ b/testing/tests/bin/memcp.cpp @@ -28,7 +28,7 @@ TEST_CASE("memcp") { } SECTION("with server") { - Server server{"memcached"}; + Server server{"memcached", {"-p", random_port_string}}; MemcachedPtr memc; LoneReturnMatcher test{*memc}; @@ -58,6 +58,7 @@ TEST_CASE("memcp") { SECTION("connection failure") { server.signal(SIGKILL); + server.tryWait(); Tempfile temp; diff --git a/testing/tests/bin/memdump.cpp b/testing/tests/bin/memdump.cpp index 6b636bca..da4ab9cb 100644 --- a/testing/tests/bin/memdump.cpp +++ b/testing/tests/bin/memdump.cpp @@ -28,7 +28,7 @@ TEST_CASE("memdump") { } SECTION("with server") { - Server server{"memcached"}; + Server server{"memcached", {"-p", random_port_string}}; MemcachedPtr memc; LoneReturnMatcher test{*memc}; @@ -53,6 +53,7 @@ TEST_CASE("memdump") { SECTION("connection failure") { server.signal(SIGKILL); + server.tryWait(); string output; REQUIRE_FALSE(sh.run(comm + "-v", output)); diff --git a/testing/tests/bin/memflush.cpp b/testing/tests/bin/memflush.cpp new file mode 100644 index 00000000..e6a759bb --- /dev/null +++ b/testing/tests/bin/memflush.cpp @@ -0,0 +1,69 @@ +#include "testing/lib/common.hpp" +#include "testing/lib/Shell.hpp" +#include "testing/lib/Server.hpp" +#include "testing/lib/Retry.hpp" +#include "testing/lib/ReturnMatcher.hpp" + +using Catch::Matchers::Contains; + +TEST_CASE("memflush") { + Shell sh{string{TESTING_ROOT "/../src/bin"}}; + + SECTION("no servers provided") { + string output; + REQUIRE_FALSE(sh.run("memflush", output)); + REQUIRE(output == "No Servers provided\n"); + } + + SECTION("--help") { + string output; + REQUIRE(sh.run("memflush --help", output)); + REQUIRE_THAT(output, Contains("memflush")); + REQUIRE_THAT(output, Contains("v1")); + REQUIRE_THAT(output, Contains("help")); + REQUIRE_THAT(output, Contains("version")); + REQUIRE_THAT(output, Contains("option")); + REQUIRE_THAT(output, Contains("--")); + REQUIRE_THAT(output, Contains("=")); + } + + SECTION("with server") { + Server server{"memcached", {"-p", random_port_string}}; + MemcachedPtr memc; + LoneReturnMatcher test{*memc}; + + server.start(); + Retry{[&server] { return server.isListening(); }}(); + auto port = get(server.getSocketOrPort()); + auto comm = "memflush --servers=localhost:" + to_string(port) + " "; + + REQUIRE_SUCCESS(memcached_server_add(*memc, "localhost", port)); + + SECTION("okay") { + + REQUIRE_SUCCESS(memcached_set(*memc, S("key1"), S("val1"), 0, 0)); + REQUIRE_SUCCESS(memcached_set(*memc, S("key2"), S("val2"), 0, 0)); + + this_thread::sleep_for(500ms); + + string output; + REQUIRE(sh.run(comm, output)); + REQUIRE(output.empty()); + + memcached_return_t rc; + REQUIRE(nullptr == memcached_get(*memc, S("key1"), nullptr, nullptr, &rc)); + REQUIRE_RC(MEMCACHED_NOTFOUND, rc); + REQUIRE(nullptr == memcached_get(*memc, S("key2"), nullptr, nullptr, &rc)); + REQUIRE_RC(MEMCACHED_NOTFOUND, rc); + } + + SECTION("connection failure") { + server.signal(SIGKILL); + server.tryWait(); + + string output; + REQUIRE_FALSE(sh.run(comm, output)); + REQUIRE_THAT(output, Contains("CONNECTION FAILURE") || Contains("SERVER HAS FAILED")); + } + } +}