1 #include "test/lib/common.hpp"
2 #include "test/lib/Cluster.hpp"
3 #include "test/lib/Retry.hpp"
4 #include "test/lib/Server.hpp"
5 #include "test/lib/Connection.hpp"
7 TEST_CASE("lib/Server") {
8 Server server
{MEMCACHED_BINARY
, {
10 Server::arg_pair_t
{"-p", random_port_string
}
13 SECTION("starts and listens") {
15 REQUIRE(server
.start().has_value());
16 REQUIRE(server
.ensureListening());
17 REQUIRE(server
.isListening());
18 REQUIRE(server
.check());
22 REQUIRE(server
.stop());
24 SECTION("is waitable") {
26 REQUIRE(server
.wait());
30 REQUIRE_FALSE(server
.check());
31 REQUIRE_FALSE(server
.isListening());
38 TEST_CASE("lib/Cluster") {
39 Cluster cluster
{Server
{MEMCACHED_BINARY
, {
40 random_socket_or_port_arg(),
43 SECTION("starts and listens") {
45 REQUIRE(cluster
.start());
46 REQUIRE(cluster
.ensureListening());
47 REQUIRE(cluster
.isListening());
56 REQUIRE(cluster
.isStopped());
57 REQUIRE_FALSE(cluster
.isListening());
63 TEST_CASE("lib/Connection") {
64 SECTION("sockaddr_un") {
66 Connection conn
{"/this/is/way/too/long/for/a/standard/unix/socket/path/living/on/this/system/at/least/i/hope/so/and/this/is/about/to/fail/for/the/sake/of/this/test.sock"};
72 Cluster cluster
{Server
{MEMCACHED_BINARY
,
74 random_socket_or_port_arg(),
76 REQUIRE(cluster
.start());
77 Retry cluster_is_listening
{[&cluster
] { return cluster
.isListening(); }};
78 REQUIRE(cluster_is_listening());
80 vector
<Connection
> conns
;
81 conns
.reserve(cluster
.getServers().size());
82 for (const auto &server
: cluster
.getServers()) {
83 CHECK_NOFAIL(conns
.emplace_back(Connection
{server
.getSocketOrPort()}).open());
85 while (!conns
.empty()) {
86 vector
<Connection
> again
;
87 again
.reserve(conns
.size());
88 for (auto &conn
: conns
) {
90 REQUIRE(conn
.isWritable());
91 REQUIRE_FALSE(conn
.getError());
93 again
.emplace_back(move(conn
));