semver: 1.0 -> 1
[awesomized/libmemcached] / test / tests / memcached / regression / lp_000-962-815.cpp
index 658c339ee19810819527eda0da476b7c48c2e179..389064db8baf7efb44fa27899525183e2401230a 100644 (file)
@@ -1,7 +1,7 @@
 #include "test/lib/common.hpp"
 #include "test/lib/MemcachedCluster.hpp"
 
-#include "libmemcachedutil-1.0/pool.h"
+#include "libmemcachedutil-1/pool.h"
 
 #include <atomic>
 #include <sstream>
@@ -17,23 +17,14 @@ static inline bool is_running() {
 
 struct worker_ctx {
   memcached_pool_st *pool;
-  vector<stringstream> errors;
 
   explicit worker_ctx(memcached_st *memc)
   : pool{memcached_pool_create(memc, 5, 10)}
-  , errors{}
   {
   }
 
   ~worker_ctx() {
     memcached_pool_destroy(pool);
-    for (const auto &err : errors) {
-      cerr << err.str() << endl;
-    }
-  }
-
-  stringstream &err() {
-    return errors[errors.size()];
   }
 };
 
@@ -42,25 +33,31 @@ static void *worker(void *arg) {
 
   while (is_running()) {
     memcached_return_t rc;
-    timespec block{5, 0};
+    timespec block{0, 1000};
     auto *mc = memcached_pool_fetch(ctx->pool, &block, &rc);
 
+    if (!mc && rc == MEMCACHED_TIMEOUT) {
+      continue;
+    }
     if (!mc || memcached_failed(rc)) {
-      ctx->err() << "failed to fetch connection from pool: "
-                 << memcached_strerror(nullptr, rc);
-      this_thread::sleep_for(100ms);
+      cerr << "failed to fetch connection from pool: "
+           << memcached_strerror(nullptr, rc)
+           << endl;
+      continue;
     }
 
     auto rs = random_ascii_string(12);
     rc = memcached_set(mc, rs.c_str(), rs.length(), rs.c_str(), rs.length(), 0, 0);
     if (memcached_failed(rc)) {
-      ctx->err() << "failed to memcached_set() "
-                 << memcached_last_error_message(mc);
+      cerr << "failed to memcached_set() "
+           << memcached_last_error_message(mc)
+           << endl;
     }
     rc = memcached_pool_release(ctx->pool, mc);
     if (memcached_failed(rc)) {
-      ctx->err() << "failed to release connection to pool: "
-                 << memcached_strerror(nullptr, rc);
+      cerr << "failed to release connection to pool: "
+           << memcached_strerror(nullptr, rc)
+           << endl;
     }
   }
 
@@ -81,7 +78,7 @@ TEST_CASE("memcached_regression_lp962815") {
     REQUIRE(0 == pthread_create(&t, nullptr, worker, &ctx));
   }
 
-  this_thread::sleep_for(5s);
+  this_thread::sleep_for(1s);
   set_running(false);
 
   for (auto t : tid) {