1 #include "testing/lib/common.hpp"
2 #include "testing/lib/Shell.hpp"
3 #include "testing/lib/Server.hpp"
4 #include "testing/lib/Retry.hpp"
5 #include "testing/lib/ReturnMatcher.hpp"
7 using Catch::Matchers::Contains
;
9 TEST_CASE("bin/memflush") {
10 Shell sh
{string
{TESTING_ROOT
"/../src/bin"}};
12 SECTION("no servers provided") {
14 REQUIRE_FALSE(sh
.run("memflush", output
));
15 REQUIRE(output
== "No Servers provided\n");
20 REQUIRE(sh
.run("memflush --help", output
));
21 REQUIRE_THAT(output
, Contains("memflush"));
22 REQUIRE_THAT(output
, Contains("v1"));
23 REQUIRE_THAT(output
, Contains("help"));
24 REQUIRE_THAT(output
, Contains("version"));
25 REQUIRE_THAT(output
, Contains("option"));
26 REQUIRE_THAT(output
, Contains("--"));
27 REQUIRE_THAT(output
, Contains("="));
30 SECTION("with server") {
31 Server server
{MEMCACHED_BINARY
, {"-p", random_port_string
}};
33 LoneReturnMatcher test
{*memc
};
36 Retry
{[&server
] { return server
.isListening(); }}();
37 auto port
= get
<int>(server
.getSocketOrPort());
38 auto comm
= "memflush --servers=localhost:" + to_string(port
) + " ";
40 REQUIRE_SUCCESS(memcached_server_add(*memc
, "localhost", port
));
44 REQUIRE_SUCCESS(memcached_set(*memc
, S("key1"), S("val1"), 0, 0));
45 REQUIRE_SUCCESS(memcached_set(*memc
, S("key2"), S("val2"), 0, 0));
47 this_thread::sleep_for(500ms
);
50 REQUIRE(sh
.run(comm
, output
));
51 REQUIRE(output
.empty());
53 memcached_return_t rc
;
54 REQUIRE(nullptr == memcached_get(*memc
, S("key1"), nullptr, nullptr, &rc
));
55 REQUIRE_RC(MEMCACHED_NOTFOUND
, rc
);
56 REQUIRE(nullptr == memcached_get(*memc
, S("key2"), nullptr, nullptr, &rc
));
57 REQUIRE_RC(MEMCACHED_NOTFOUND
, rc
);
60 SECTION("connection failure") {
61 server
.signal(SIGKILL
);
65 REQUIRE_FALSE(sh
.run(comm
, output
));
66 REQUIRE_THAT(output
, Contains("CONNECTION FAILURE") || Contains("SERVER HAS FAILED"));