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)
+- 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 (!!!)
add_subdirectory(libmemcached)
add_subdirectory(libmemcachedutil)
add_subdirectory(libmemcachedprotocol)
-
-if(BUILD_TESTING)
- add_subdirectory(libtest)
-endif()
+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")
}
SECTION("with server") {
- Server server{"memcached"};
+ Server server{"memcached", {"-p", random_port_string}};
MemcachedPtr memc;
LoneReturnMatcher test{*memc};
}
SECTION("with server") {
- Server server{"memcached"};
+ Server server{"memcached", {"-p", random_port_string}};
MemcachedPtr memc;
LoneReturnMatcher test{*memc};
SECTION("connection failure") {
server.signal(SIGKILL);
+ server.tryWait();
Tempfile temp;
}
SECTION("with server") {
- Server server{"memcached"};
+ Server server{"memcached", {"-p", random_port_string}};
MemcachedPtr memc;
LoneReturnMatcher test{*memc};
SECTION("connection failure") {
server.signal(SIGKILL);
+ server.tryWait();
string output;
REQUIRE_FALSE(sh.run(comm + "-v", output));
--- /dev/null
+#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<int>(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"));
+ }
+ }
+}