testing: test lib/Connection
authorMichael Wallner <mike@php.net>
Sun, 25 Oct 2020 06:54:58 +0000 (07:54 +0100)
committerMichael Wallner <mike@php.net>
Sun, 25 Oct 2020 06:54:58 +0000 (07:54 +0100)
test/tests/lib.cpp

index ab5bc7f5e04a529e3c9646620fcc34b6a571aa86..76e6516eb5f8d00eb33cb9a18ec7b1975f828952 100644 (file)
@@ -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<Connection> conns;
+    conns.reserve(cluster.getServers().size());
+    for (const auto &server : cluster.getServers()) {
+      REQUIRE(conns.emplace_back(Connection{server.getSocketOrPort()}).open());
+    }
+    while (!conns.empty()) {
+      vector<Connection> 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);
+    }
+  }
+}