Skip to content

Commit

Permalink
Merge branch 'fix/php-memcached-531' into v1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
m6w6 committed Mar 6, 2023
2 parents 60f8b54 + 7163bb2 commit f589922
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/libmemcached/purge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ bool memcached_purge(memcached_instance_st *ptr) {
WATCHPOINT_ERROR(rc);
is_successful = false;
}
if (rc == MEMCACHED_TIMEOUT) {
break;
}

if (ptr->root->callbacks) {
memcached_callback_st cb = *ptr->root->callbacks;
Expand Down
2 changes: 1 addition & 1 deletion src/libmemcached/response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ static memcached_return_t _read_one_response(memcached_instance_st *instance, ch
rc = textual_read_one_response(instance, buffer, buffer_length, result);
}

if (memcached_fatal(rc) && rc != MEMCACHED_TIMEOUT) {
if (memcached_fatal(rc)) {
memcached_io_reset(instance);
}

Expand Down
12 changes: 4 additions & 8 deletions test/tests/memcached/noblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TEST_CASE("memcached_noblock") {
REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1));
REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout));

auto num = timeout ? 10'000 : 1'000'000;
auto num = 10000;
auto hit = 0u;
auto rnd = random_ascii_string(512);
for (auto i = 0; i < num; ++i) {
Expand All @@ -23,20 +23,16 @@ TEST_CASE("memcached_noblock") {
break;
case MEMCACHED_TIMEOUT:
case MEMCACHED_WRITE_FAILURE:
if(!timeout) {
--i;
}
++hit;
REQUIRE(true);
break;
default:
REQUIRE(false);
}
}
INFO("failures triggered: " << hit);
INFO("timeout=" << timeout << " failures triggered: " << hit);
if (timeout) {
CHECK_FALSE(hit);
REQUIRE_FALSE(hit);
} else {
CHECK(hit > 0);
REQUIRE(hit > 0);
}
}
29 changes: 29 additions & 0 deletions test/tests/memcached/regression/gh-php-memcached_0531.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "test/lib/common.hpp"
#include "test/lib/MemcachedCluster.hpp"

TEST_CASE("memcached_regression_gh-php-memcached_0531") {
auto test = MemcachedCluster{Cluster{Server{MEMCACHED_BINARY, {"-p", random_socket_or_port_string("-p")}}, 1}};
auto memc = &test.memc;
auto nonblock = GENERATE(0, 1);

INFO("nonblock=" << nonblock);

REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, nonblock));

REQUIRE_SUCCESS(memcached_set(memc, S("first"), S("first"), 0, 0));
REQUIRE_SUCCESS(memcached_set(memc, S("second"), S("second"), 0, 0));

REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, 0));

memcached_return_t rc;
size_t len;
Malloced value1(memcached_get(memc, S("first"), &len, nullptr, &rc));
REQUIRE_RC(MEMCACHED_TIMEOUT, rc);
REQUIRE_FALSE(*value1);

REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, 100));

Malloced value2(memcached_get(memc, S("second"), &len, nullptr, &rc));
REQUIRE_SUCCESS(rc);
REQUIRE(string(*value2) == string("second"));
}

0 comments on commit f589922

Please sign in to comment.