update TODO
[awesomized/libmemcached] / test / tests / bin / memstat.cpp
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"
6
7 using Catch::Matchers::Contains;
8
9 TEST_CASE("bin/memstat") {
10 Shell sh{string{TESTING_ROOT "/../src/bin"}};
11
12 SECTION("no servers provided") {
13 string output;
14 REQUIRE_FALSE(sh.run("memstat", output));
15 REQUIRE(output == "No servers provided.\n");
16 }
17
18 SECTION("--help") {
19 string output;
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"));
29 }
30
31 SECTION("with server") {
32 Server server{MEMCACHED_BINARY, {"-p", random_port_string}};
33 MemcachedPtr memc;
34 LoneReturnMatcher test{*memc};
35
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) + " ";
40
41 REQUIRE_SUCCESS(memcached_server_add(*memc, "localhost", port));
42
43 SECTION("okay") {
44 SECTION("stat") {
45 string output;
46 REQUIRE(sh.run(comm, output));
47 REQUIRE_THAT(output, Contains("Server:"));
48 REQUIRE_THAT(output, Contains("pid:"));
49 }
50 SECTION("version") {
51 REQUIRE_SUCCESS(memcached_version(*memc));
52 auto inst = memcached_server_instance_by_position(*memc, 0);
53
54 string output;
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))));
60 }
61 SECTION("analyze") {
62 string output;
63 REQUIRE(sh.run(comm + "--analyze", output));
64 REQUIRE_THAT(output, Contains("Number of Servers Analyzed : 2"));
65 }
66 SECTION("analyze=latency") {
67 string output;
68 REQUIRE(sh.run(comm + "--analyze=latency", output));
69 REQUIRE_THAT(output, Contains("Network Latency Test:"));
70 }
71 }
72
73 SECTION("connection failure") {
74 server.signal(SIGKILL);
75 server.wait();
76
77 string output;
78 REQUIRE_FALSE(sh.run(comm + "--analyze", output));
79 REQUIRE_THAT(output,
80 Contains("CONNECTION FAILURE")
81 || Contains("SERVER HAS FAILED")
82 || Contains("SYSTEM ERROR")
83 || Contains("TIMEOUT OCCURRED"));
84 }
85 }
86 }