#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>
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()];
}
};
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;
}
}
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) {