1 #include "test/lib/common.hpp"
2 #include "test/lib/Shell.hpp"
3 #include "test/lib/Server.hpp"
4 #include "test/lib/Retry.hpp"
5 #include "test/lib/ReturnMatcher.hpp"
7 using Catch::Matchers::Contains
;
9 TEST_CASE("bin/memstat") {
10 Shell sh
{string
{TESTING_ROOT
"/../src/bin"}};
12 SECTION("no servers provided") {
14 REQUIRE_FALSE(sh
.run("memstat", output
));
15 REQUIRE(output
== "No servers provided.\n");
20 REQUIRE(sh
.run("memstat --help", output
));
21 REQUIRE_THAT(output
, Contains("memstat v1"));
22 REQUIRE_THAT(output
, Contains("Usage:"));
23 REQUIRE_THAT(output
, Contains("[stat ...]"));
24 REQUIRE_THAT(output
, Contains("Options:"));
25 REQUIRE_THAT(output
, Contains("-h|--help"));
26 REQUIRE_THAT(output
, Contains("-V|--version"));
27 REQUIRE_THAT(output
, Contains("Environment:"));
28 REQUIRE_THAT(output
, Contains("MEMCACHED_SERVERS"));
31 SECTION("with server") {
32 Server server
{MEMCACHED_BINARY
, {"-p", random_port_string
}};
34 LoneReturnMatcher test
{*memc
};
36 REQUIRE(server
.ensureListening());
37 auto port
= get
<int>(server
.getSocketOrPort());
38 auto comm
= "memstat --servers=localhost:" + to_string(port
)
39 + ",localhost:" + to_string(port
) + " ";
41 REQUIRE_SUCCESS(memcached_server_add(*memc
, "localhost", port
));
46 REQUIRE(sh
.run(comm
, output
));
47 REQUIRE_THAT(output
, Contains("Server:"));
48 REQUIRE_THAT(output
, Contains("pid:"));
51 REQUIRE_SUCCESS(memcached_version(*memc
));
52 auto inst
= memcached_server_instance_by_position(*memc
, 0);
55 REQUIRE(sh
.run(comm
+ "--server-version", output
));
56 REQUIRE_THAT(output
, Contains("localhost:" + to_string(port
) + " "
57 + to_string(memcached_server_major_version(inst
)) + "."
58 + to_string(memcached_server_minor_version(inst
)) + "."
59 + to_string(memcached_server_micro_version(inst
))));
63 REQUIRE(sh
.run(comm
+ "--analyze", output
));
64 REQUIRE_THAT(output
, Contains("Number of Servers Analyzed : 2"));
66 SECTION("analyze=latency") {
68 REQUIRE(sh
.run(comm
+ "--analyze=latency", output
));
69 REQUIRE_THAT(output
, Contains("Network Latency Test:"));
73 SECTION("connection failure") {
74 server
.signal(SIGKILL
);
78 REQUIRE_FALSE(sh
.run(comm
+ "--analyze", output
));
80 Contains("CONNECTION FAILURE")
81 || Contains("SERVER HAS FAILED")
82 || Contains("SYSTEM ERROR")
83 || Contains("TIMEOUT OCCURRED"));