From: Michael Wallner Date: Wed, 7 Oct 2020 06:56:17 +0000 (+0200) Subject: testing: pools + mac X-Git-Tag: 1.1.0-beta1~236^2~17 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=633cf1561c54972aea6a12babc4cf38c679b8ceb;p=awesomized%2Flibmemcached testing: pools + mac --- diff --git a/test/tests/memcached/regression/lp_000-962-815.cpp b/test/tests/memcached/regression/lp_000-962-815.cpp index 5c168a12..bde4dfce 100644 --- a/test/tests/memcached/regression/lp_000-962-815.cpp +++ b/test/tests/memcached/regression/lp_000-962-815.cpp @@ -17,24 +17,14 @@ static inline bool is_running() { struct worker_ctx { memcached_pool_st *pool; - vector 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() { - errors.resize(errors.size()+1); - return errors[errors.size()-1]; } }; @@ -53,7 +43,6 @@ static void *worker(void *arg) { cerr << "failed to fetch connection from pool: " << memcached_strerror(nullptr, rc) << endl; - this_thread::sleep_for(10ms); continue; } @@ -89,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) { diff --git a/test/tests/memcached/util_pool_thread.cpp b/test/tests/memcached/util_pool_thread.cpp index 55e9a027..0f90a008 100644 --- a/test/tests/memcached/util_pool_thread.cpp +++ b/test/tests/memcached/util_pool_thread.cpp @@ -1,14 +1,11 @@ #include "test/lib/common.hpp" -#include "libmemcachedutil-1.0/pool.h" - -#include - #if HAVE_SEMAPHORE_H +#include "libmemcachedutil-1.0/pool.h" +#include #include "semaphore.h" -#ifndef __APPLE__ struct test_pool_context_st { volatile memcached_return_t rc; memcached_pool_st *pool; @@ -19,7 +16,9 @@ struct test_pool_context_st { rc(MEMCACHED_FAILURE), pool(pool_arg), memc(memc_arg) { - sem_init(&_lock, 0, 0); + if (sem_init(&_lock, 0, 0)) { + perror("sem_init()"); + } } void wait() { @@ -38,19 +37,15 @@ struct test_pool_context_st { static void *connection_release(void *arg) { assert(arg != nullptr); - this_thread::sleep_for(2s); + this_thread::sleep_for(200ms); auto res = static_cast(arg); res->rc = memcached_pool_release(res->pool, res->memc); res->release(); pthread_exit(arg); } -#endif TEST_CASE("memcached_util_pool_thread") { -#ifdef __APPLE__ - SUCCEED("skip: pthreads"); -#else MemcachedPtr memc; auto pool = memcached_pool_create(*memc, 1, 1); REQUIRE(pool); @@ -75,8 +70,6 @@ TEST_CASE("memcached_util_pool_thread") { item.wait(); memcached_st *pop_memc; - // We do a hard loop, and try N times - int counter = 5; do { struct timespec relative_time = {0, 0}; pop_memc = memcached_pool_fetch(pool, &relative_time, &rc); @@ -89,7 +82,7 @@ TEST_CASE("memcached_util_pool_thread") { REQUIRE_FALSE(pop_memc); REQUIRE(rc != MEMCACHED_TIMEOUT); // As long as relative_time is zero, MEMCACHED_TIMEOUT is invalid } - } while (--counter); + } while (rc == MEMCACHED_NOTFOUND); // Cleanup thread since we will exit once we test. REQUIRE(0 == pthread_join(tid, nullptr)); @@ -98,7 +91,6 @@ TEST_CASE("memcached_util_pool_thread") { REQUIRE(MEMCACHED_SUCCESS == memcached_pool_release(pool, pop_memc)); REQUIRE(memcached_pool_destroy(pool) == *memc); -#endif // __APPLE__ } #endif // HAVE_SEMAPHORE_H