|
10 | 10 | #include <utility> |
11 | 11 | #include <vector> |
12 | 12 |
|
| 13 | +#include <fmt/core.h> |
| 14 | +#include <glog/logging.h> |
13 | 15 | #include <gtest/gtest.h> |
14 | 16 |
|
15 | 17 | #include <folly/fibers/Baton.h> |
16 | 18 | #include <folly/io/async/EventBase.h> |
| 19 | +#include <thrift/lib/cpp2/util/ScopedServerInterfaceThread.h> |
17 | 20 |
|
18 | 21 | #include "mcrouter/CarbonRouterClient.h" |
19 | 22 | #include "mcrouter/CarbonRouterInstance.h" |
20 | 23 | #include "mcrouter/ExecutorObserver.h" |
21 | 24 | #include "mcrouter/McReqUtil.h" |
22 | 25 | #include "mcrouter/Proxy.h" |
| 26 | +#include "mcrouter/ProxyDestinationMap.h" |
23 | 27 | #include "mcrouter/config.h" |
24 | 28 | #include "mcrouter/lib/carbon/RequestReplyUtil.h" |
25 | 29 | #include "mcrouter/lib/carbon/example/gen/HelloGoodbyeRouterInfo.h" |
|
28 | 32 | #include "mcrouter/lib/network/AsyncMcServerWorker.h" |
29 | 33 | #include "mcrouter/lib/network/McServerRequestContext.h" |
30 | 34 | #include "mcrouter/lib/network/gen/MemcacheRouterInfo.h" |
| 35 | +#include "mcrouter/lib/network/gen/gen-cpp2/Memcache.h" |
31 | 36 |
|
32 | 37 | #include "mcrouter/stats.h" |
33 | 38 |
|
34 | 39 | using facebook::memcache::McGetReply; |
35 | 40 | using facebook::memcache::McGetRequest; |
36 | 41 | using facebook::memcache::McStatsReply; |
37 | 42 | using facebook::memcache::McStatsRequest; |
| 43 | +using facebook::memcache::McVersionReply; |
| 44 | +using facebook::memcache::McVersionRequest; |
38 | 45 | using facebook::memcache::MemcacheRouterInfo; |
39 | 46 | using facebook::memcache::mcrouter::CarbonRouterClient; |
40 | 47 | using facebook::memcache::mcrouter::CarbonRouterInstance; |
@@ -756,3 +763,59 @@ TEST(CarbonRouterClient, requestExpiryTestWithLatencyInjectionRoute) { |
756 | 763 | server.shutdown(); |
757 | 764 | EXPECT_TRUE(replyReceived); |
758 | 765 | } |
| 766 | + |
| 767 | +class TkoProbeHandler final : public apache::thrift::ServiceHandler< |
| 768 | + facebook::memcache::thrift::Memcache> { |
| 769 | + public: |
| 770 | + void async_eb_mcGet( |
| 771 | + apache::thrift::HandlerCallbackPtr<McGetReply> callback, |
| 772 | + const McGetRequest&) override final { |
| 773 | + callback->result(McGetReply(carbon::Result::TIMEOUT)); |
| 774 | + } |
| 775 | + |
| 776 | + void async_eb_mcVersion( |
| 777 | + apache::thrift::HandlerCallbackPtr<McVersionReply> callback, |
| 778 | + const McVersionRequest&) override final { |
| 779 | + versionRequested_.post(); |
| 780 | + callback->result(McVersionReply(carbon::Result::OK)); |
| 781 | + } |
| 782 | + |
| 783 | + folly::fibers::Baton& versionRequested() { |
| 784 | + return versionRequested_; |
| 785 | + } |
| 786 | + |
| 787 | + private: |
| 788 | + folly::fibers::Baton versionRequested_; |
| 789 | +}; |
| 790 | + |
| 791 | +TEST(CarbonRouterInstance, disableProbesPreventsScheduledTkoProbe) { |
| 792 | + auto handler = std::make_shared<TkoProbeHandler>(); |
| 793 | + apache::thrift::ScopedServerInterfaceThread server(handler, "127.0.0.1", 0); |
| 794 | + |
| 795 | + auto opts = defaultTestOptions(); |
| 796 | + opts.failures_until_tko = 1; |
| 797 | + opts.probe_delay_initial_ms = 1; |
| 798 | + opts.config_str = fmt::format( |
| 799 | + R"({{"route":{{"type":"PoolRoute","pool":{{"name":"A","servers":["127.0.0.1:{}"],"protocol":"thrift"}}}}}})", |
| 800 | + server.getPort()); |
| 801 | + auto router = CarbonRouterInstance<MemcacheRouterInfo>::init( |
| 802 | + "disableProbesPreventsScheduledTkoProbe", opts); |
| 803 | + |
| 804 | + auto& proxy = *CHECK_NOTNULL(router->getProxy(0)); |
| 805 | + auto client = router->createClient(0, false); |
| 806 | + auto& clientRef = *CHECK_NOTNULL(client.get()); |
| 807 | + folly::fibers::Baton replyReceived; |
| 808 | + const McGetRequest request("key"); |
| 809 | + clientRef.send( |
| 810 | + request, |
| 811 | + [&proxy, &replyReceived](const McGetRequest&, McGetReply&& reply) { |
| 812 | + EXPECT_EQ(carbon::Result::TIMEOUT, *reply.result()); |
| 813 | + proxy.destinationMap()->disableProbes(); |
| 814 | + replyReceived.post(); |
| 815 | + }); |
| 816 | + replyReceived.wait(); |
| 817 | + |
| 818 | + EXPECT_FALSE( |
| 819 | + handler->versionRequested().try_wait_for(std::chrono::seconds(1))); |
| 820 | + router->shutdown(); |
| 821 | +} |
0 commit comments