ci: gh-actions: package: exclude only conflicting ubuntu18-gnu-new
[awesomized/libmemcached] / test / tests / lib.cpp
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"
6
7 TEST_CASE("lib/Server") {
8 Server server{MEMCACHED_BINARY, {
9 Server::arg_t{"-v"},
10 Server::arg_pair_t{"-p", random_port_string}
11 }};
12
13 SECTION("starts and listens") {
14
15 REQUIRE(server.start().has_value());
16 REQUIRE(server.ensureListening());
17 REQUIRE(server.isListening());
18 REQUIRE(server.check());
19
20 SECTION("stops") {
21
22 REQUIRE(server.stop());
23
24 SECTION("is waitable") {
25
26 REQUIRE(server.wait());
27
28 SECTION("stopped") {
29
30 REQUIRE_FALSE(server.check());
31 REQUIRE_FALSE(server.isListening());
32 }
33 }
34 }
35 }
36 }
37
38 TEST_CASE("lib/Cluster") {
39 Cluster cluster{Server{MEMCACHED_BINARY, {
40 random_socket_or_port_arg(),
41 }}};
42
43 SECTION("starts and listens") {
44
45 REQUIRE(cluster.start());
46 REQUIRE(cluster.ensureListening());
47 REQUIRE(cluster.isListening());
48
49 SECTION("stops") {
50
51 cluster.stop();
52 cluster.wait();
53
54 SECTION("stopped") {
55
56 REQUIRE(cluster.isStopped());
57 REQUIRE_FALSE(cluster.isListening());
58 }
59 }
60 }
61 }
62
63 TEST_CASE("lib/Connection") {
64 SECTION("sockaddr_un") {
65 auto f = []{
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"};
67 return conn;
68 };
69 REQUIRE_THROWS(f());
70 }
71 SECTION("connect") {
72 Cluster cluster{Server{MEMCACHED_BINARY,
73 {
74 random_socket_or_port_arg(),
75 }}};
76 REQUIRE(cluster.start());
77 Retry cluster_is_listening{[&cluster] { return cluster.isListening(); }};
78 REQUIRE(cluster_is_listening());
79
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());
84 }
85 while (!conns.empty()) {
86 vector<Connection> again;
87 again.reserve(conns.size());
88 for (auto &conn : conns) {
89 if (conn.isOpen()) {
90 REQUIRE(conn.isWritable());
91 REQUIRE_FALSE(conn.getError());
92 } else {
93 again.emplace_back(move(conn));
94 }
95 }
96 conns.swap(again);
97 }
98 }
99 }