From: Michael Wallner Date: Sun, 25 Oct 2020 06:54:58 +0000 (+0100) Subject: testing: test lib/Connection X-Git-Tag: 1.1.0-beta1~161 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=1960570c4af5cb5f85523609cd79bf720495f6f4;p=m6w6%2Flibmemcached testing: test lib/Connection --- diff --git a/test/tests/lib.cpp b/test/tests/lib.cpp index ab5bc7f5..76e6516e 100644 --- a/test/tests/lib.cpp +++ b/test/tests/lib.cpp @@ -2,6 +2,7 @@ #include "test/lib/Cluster.hpp" #include "test/lib/Retry.hpp" #include "test/lib/Server.hpp" +#include "test/lib/Connection.hpp" TEST_CASE("lib/Server") { Server server{MEMCACHED_BINARY, { @@ -61,3 +62,41 @@ TEST_CASE("lib/Cluster") { } } } + +TEST_CASE("lib/Connection") { + SECTION("sockaddr_un") { + auto f = []{ + 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"}; + return conn; + }; + REQUIRE_THROWS(f()); + } + SECTION("connect") { + Cluster cluster{Server{MEMCACHED_BINARY, + { + random_socket_or_port_arg(), + }}}; + REQUIRE(cluster.start()); + Retry cluster_is_listening{[&cluster] { return cluster.isListening(); }}; + REQUIRE(cluster_is_listening()); + + vector conns; + conns.reserve(cluster.getServers().size()); + for (const auto &server : cluster.getServers()) { + REQUIRE(conns.emplace_back(Connection{server.getSocketOrPort()}).open()); + } + while (!conns.empty()) { + vector again; + again.reserve(conns.size()); + for (auto &conn : conns) { + if (conn.isOpen()) { + REQUIRE(conn.isWritable()); + REQUIRE_FALSE(conn.getError()); + } else { + again.emplace_back(move(conn)); + } + } + conns.swap(again); + } + } +}