Skip to content

Commit

Permalink
test: poll_timeout; see php-memcached-dev/php-memcached#531
Browse files Browse the repository at this point in the history
  • Loading branch information
m6w6 committed Mar 1, 2023
1 parent 279113c commit 11ad514
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/tests/memcached/poll_timeout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "test/lib/common.hpp"
#include "test/lib/MemcachedCluster.hpp"

TEST_CASE("memcached_poll_timeout") {
auto test = MemcachedCluster::network();
auto memc = &test.memc;

REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 1));
REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1));
REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 0));
REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, 20));
REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RCV_TIMEOUT, 20*1000));
REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SND_TIMEOUT, 20*1000));
REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 60));
REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, 20));


memcached_return_t rc;
size_t len;

auto num = 500;
auto hit = 0u;
auto rnd = random_ascii_string(128);

REQUIRE_SUCCESS(memcached_flush(memc, 0));

for (auto i = 0; i < num; ++i) {
auto setKey = rnd + to_string(i);
REQUIRE_SUCCESS(memcached_set(memc, setKey.c_str(), setKey.length(), setKey.c_str(),
setKey.length(), 1, 0));
}
memcached_quit(memc);

auto timeoutAchieved = false;
for (auto i = 0; i < num; ++i) {
for (auto j = 0; j < i; ++j) {
auto getKey = rnd + to_string(j);
auto len = getKey.length();
char key[MEMCACHED_MAX_KEY];
memcpy(key, getKey.c_str(), len + 1);
const char *keys[1] = {key};
std::cerr << int(timeoutAchieved);

REQUIRE_SUCCESS(memcached_mget(memc, keys, &len, 1));
auto numResults = 0;
while (auto rv = memcached_fetch(memc, key, nullptr, &len, nullptr, &rc)) {
REQUIRE(!timeoutAchieved);

REQUIRE_SUCCESS(rc);
free(rv);

numResults++;
REQUIRE(numResults == 1);
}

if (MEMCACHED_END == rc || MEMCACHED_NOTFOUND == rc ){
continue;
}

if (MEMCACHED_TIMEOUT == rc){
timeoutAchieved = true;
continue;
}

INFO(rc);
REQUIRE(false);
}
}
}

0 comments on commit 11ad514

Please sign in to comment.