bin: consolidate clients
[awesomized/libmemcached] / test / tests / memcached / noblock.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
3
4 TEST_CASE("memcached_noblock") {
5 auto test = MemcachedCluster::network();
6 auto memc = &test.memc;
7 auto timeout = GENERATE(0, -1);
8
9 REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 1));
10 REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1));
11 REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout));
12
13 auto num = timeout ? 10'000 : 1'000'000;
14 auto hit = 0u;
15 auto rnd = random_ascii_string(512);
16 for (auto i = 0; i < num; ++i) {
17 auto key = to_string(i);
18 auto rc = memcached_set(memc, key.c_str(), key.length(), rnd.c_str(), rnd.length(), 1, 0);
19 switch (rc) {
20 case MEMCACHED_SUCCESS:
21 case MEMCACHED_BUFFERED:
22 case MEMCACHED_SERVER_TEMPORARILY_DISABLED:
23 break;
24 case MEMCACHED_TIMEOUT:
25 case MEMCACHED_WRITE_FAILURE:
26 if(!timeout) {
27 --i;
28 }
29 ++hit;
30 REQUIRE(true);
31 break;
32 default:
33 REQUIRE(false);
34 }
35 }
36 INFO("failures triggered: " << hit);
37 if (timeout) {
38 CHECK_FALSE(hit);
39 } else {
40 CHECK(hit > 0);
41 }
42 }