testing: freebsd [travis skip]
[m6w6/libmemcached] / test / tests / memcached / udp.cpp
index 85e44126c7ae742becda21bddf4bc6470408960c..a12e42d6f5a86872c5a27e782187011f3579f802 100644 (file)
@@ -2,30 +2,14 @@
 #include "test/lib/MemcachedCluster.hpp"
 
 TEST_CASE("memcached_udp") {
-#ifdef __APPLE__
-  WARN("skip: memcached crashes");
-  SUCCEED();
-#else
   auto test = MemcachedCluster::udp();
   auto memc = &test.memc;
+  MemcachedPtr check;
 
-  SECTION("sets reply flag") {
-    // FIXME: bad internals test
-    REQUIRE(memc->flags.reply);
-    REQUIRE_FALSE(memc->flags.use_udp);
-    REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply);
-    test.enableUdp();
-    REQUIRE_FALSE(memc->flags.reply);
-    REQUIRE(memc->flags.use_udp);
-    REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply);
-    test.enableUdp(false);
-    REQUIRE(memc->flags.reply);
-    REQUIRE_FALSE(memc->flags.use_udp);
-    REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply);
+  for (const auto &server : test.cluster.getServers()) {
+    memcached_server_add(*check, "localhost", get<int>(server.getSocketOrPort()));
   }
 
-  test.enableUdp();
-
   SECTION("compat") {
     memcached_return_t rc;
     REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true));
@@ -40,7 +24,7 @@ TEST_CASE("memcached_udp") {
 
   SECTION("io") {
     const auto max = 1025; // request id rolls over at 1024
-    auto binary = GENERATE(0,1);
+    auto binary = GENERATE(0, 1);
 
     test.enableBinaryProto(binary);
 
@@ -51,9 +35,17 @@ TEST_CASE("memcached_udp") {
           INFO("i=" << i);
           REQUIRE_SUCCESS(memcached_set(memc, s.c_str(), s.length(), s.c_str(), s.length(), 0, 0));
         }
-        // FIXME: check request id
         memcached_quit(memc);
         REQUIRE_SUCCESS(memcached_last_error(memc));
+
+        for (auto i = 0; i < max; ++i) {
+          auto s = to_string(i);
+          memcached_return_t rc;
+          INFO("i=" << i);
+          Malloced val(memcached_get(*check, s.c_str(), s.length(), nullptr, nullptr, &rc));
+          CHECK(*val);
+          CHECK(MEMCACHED_SUCCESS == rc);
+        }
       }
 
       SECTION("set too big") {
@@ -91,7 +83,30 @@ TEST_CASE("memcached_udp") {
         memcached_quit(memc);
         REQUIRE_SUCCESS(memcached_last_error(memc));
       }
+
+      SECTION("incremend/decrement") {
+        uint64_t newval = 0;
+        REQUIRE_SUCCESS(memcached_set(memc, S("udp-incr"), S("1"), 0, 0));
+        memcached_quit(memc);
+        this_thread::sleep_for(1s);
+        REQUIRE_SUCCESS(memcached_increment(memc, S("udp-incr"), 1, &newval));
+        memcached_quit(memc);
+        this_thread::sleep_for(1s);
+        REQUIRE(newval == UINT64_MAX);
+        memcached_return_t rc;
+        Malloced val(memcached_get(*check, S("udp-incr"), nullptr, nullptr, &rc));
+        REQUIRE_SUCCESS(rc);
+        REQUIRE(*val);
+        CHECK(string(*val) == "2");
+        REQUIRE_SUCCESS(memcached_decrement(memc, S("udp-incr"), 1, &newval));
+        memcached_quit(memc);
+        this_thread::sleep_for(1s);
+        REQUIRE(newval == UINT64_MAX);
+        val = memcached_get(*check, S("udp-incr"), nullptr, nullptr, &rc);
+        REQUIRE_SUCCESS(rc);
+        REQUIRE(*val);
+        CHECK(string(*val) == "1");
+      }
     }
   }
-#endif
 }