From: Michael Wallner Date: Wed, 7 Oct 2020 13:53:00 +0000 (+0200) Subject: testing: udp flag must be set prior adding servers X-Git-Tag: 1.1.0-beta1~236^2~13 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=fe7194f7d6348559fc9219d9899c9633c9de77f2;p=awesomized%2Flibmemcached testing: udp flag must be set prior adding servers --- diff --git a/test/lib/MemcachedCluster.cpp b/test/lib/MemcachedCluster.cpp index bb164e5d..06e2c7f1 100644 --- a/test/lib/MemcachedCluster.cpp +++ b/test/lib/MemcachedCluster.cpp @@ -29,6 +29,11 @@ void MemcachedCluster::init() { } REQUIRE(memcached_create(&memc)); + + for (const auto &[behavior, value] : to_set) { + REQUIRE(MEMCACHED_SUCCESS == memcached_behavior_set(&memc, behavior, value)); + } + for (const auto &server : cluster.getServers()) { auto target = server.getSocketOrPort(); if (holds_alternative(target)) { @@ -59,8 +64,9 @@ MemcachedCluster::MemcachedCluster() init(); } -MemcachedCluster::MemcachedCluster(Cluster &&cluster_) +MemcachedCluster::MemcachedCluster(Cluster &&cluster_, behaviors_t to_set_) : cluster{move(cluster_)} +, to_set{move(to_set_)} { init(); } @@ -103,7 +109,9 @@ MemcachedCluster MemcachedCluster::udp() { Server::arg_pair_t{"-U", random_socket_or_port_string}, Server::arg_t{"-v"} } - }}}; + }}, { + {MEMCACHED_BEHAVIOR_USE_UDP, 1} + }}; } #if LIBMEMCACHED_WITH_SASL_SUPPORT @@ -114,8 +122,9 @@ MemcachedCluster MemcachedCluster::sasl() { Server::arg_pair_t{"-p", random_socket_or_port_string}, Server::arg_t{"-S"} } - }}}; - mc.enableBinaryProto(); + }}, { + {MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1}, + }}; REQUIRE(MEMCACHED_SUCCESS == memcached_set_sasl_auth_data(&mc.memc, "memcached", "memcached")); return mc; @@ -137,11 +146,6 @@ void MemcachedCluster::enableReplication() { MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, memcached_server_count(&memc) - 1)); } -void MemcachedCluster::enableUdp(bool enable) { - REQUIRE(MEMCACHED_SUCCESS == memcached_behavior_set(&memc, - MEMCACHED_BEHAVIOR_USE_UDP, enable)); -} - void MemcachedCluster::killOneServer() { const auto &servers = cluster.getServers(); const auto &victim = servers[random_num(0UL, servers.size() - 1)]; diff --git a/test/lib/MemcachedCluster.hpp b/test/lib/MemcachedCluster.hpp index 5dbe5c2c..0a4dcb6b 100644 --- a/test/lib/MemcachedCluster.hpp +++ b/test/lib/MemcachedCluster.hpp @@ -7,19 +7,21 @@ class MemcachedCluster { public: + using behavior_t = pair; + using behaviors_t = vector; + Cluster cluster; memcached_st memc{empty_memc}; ReturnMatcher returns{&memc}; MemcachedCluster(); - explicit - MemcachedCluster(Cluster &&cluster); + explicit MemcachedCluster(Cluster &&cluster, behaviors_t to_set = {}); ~MemcachedCluster(); MemcachedCluster(const MemcachedCluster &) = delete; MemcachedCluster &operator=(const MemcachedCluster &) = delete; - MemcachedCluster(MemcachedCluster &&mc);; + MemcachedCluster(MemcachedCluster &&mc); MemcachedCluster &operator=(MemcachedCluster &&mc); void enableBinaryProto(bool enable = true); @@ -40,6 +42,7 @@ public: void killOneServer(); private: + behaviors_t to_set; static const memcached_st empty_memc; void init(); diff --git a/test/tests/memcached/udp.cpp b/test/tests/memcached/udp.cpp index 85e44126..ad242145 100644 --- a/test/tests/memcached/udp.cpp +++ b/test/tests/memcached/udp.cpp @@ -9,23 +9,6 @@ TEST_CASE("memcached_udp") { auto test = MemcachedCluster::udp(); auto memc = &test.memc; - SECTION("sets reply flag") { - // FIXME: bad internals test - REQUIRE(memc->flags.reply); - REQUIRE_FALSE(memc->flags.use_udp); - REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply); - test.enableUdp(); - REQUIRE_FALSE(memc->flags.reply); - REQUIRE(memc->flags.use_udp); - REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply); - test.enableUdp(false); - REQUIRE(memc->flags.reply); - REQUIRE_FALSE(memc->flags.use_udp); - REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply); - } - - test.enableUdp(); - SECTION("compat") { memcached_return_t rc; REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true));