From a290cd61bc2195f6aad3289ed9b6811a872ca3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Szab=C3=B3?= Date: Mon, 29 Jul 2024 00:59:05 +0200 Subject: [PATCH] Start fixing tests --- .../network/test/AsyncMcClientTestSync.cpp | 6 +++ mcrouter/lib/network/test/MockMc.cpp | 4 ++ mcrouter/lib/network/test/MockMc.h | 2 + mcrouter/lib/network/test/MockMcOnRequest.h | 1 + .../lib/network/test/TestClientServerUtil.cpp | 2 + mcrouter/test/MCProcess.py | 9 +++- .../cpp_unit_tests/McrouterClientUsage.cpp | 1 + mcrouter/test/test_unknown_name_handle.json | 46 +++++++++---------- 8 files changed, 46 insertions(+), 25 deletions(-) diff --git a/mcrouter/lib/network/test/AsyncMcClientTestSync.cpp b/mcrouter/lib/network/test/AsyncMcClientTestSync.cpp index cd3278ce1..b81e00dcb 100644 --- a/mcrouter/lib/network/test/AsyncMcClientTestSync.cpp +++ b/mcrouter/lib/network/test/AsyncMcClientTestSync.cpp @@ -1143,6 +1143,9 @@ TEST_P(AsyncMcClientSSLOffloadTest, closeNow) { EXPECT_FALSE(upCalled); EXPECT_TRUE(downReason.has_value()); EXPECT_EQ(*downReason, ConnectionDownReason::ABORTED); + + server->shutdown(); + server->join(); } TEST_P(AsyncMcClientSSLOffloadTest, clientReset) { @@ -1164,6 +1167,9 @@ TEST_P(AsyncMcClientSSLOffloadTest, clientReset) { evb.loopOnce(); client.reset(); evb.loop(); + + server->shutdown(); + server->join(); } INSTANTIATE_TEST_CASE_P(AsyncMcClientTest, AsyncMcClientSSLOffloadTest, Bool()); diff --git a/mcrouter/lib/network/test/MockMc.cpp b/mcrouter/lib/network/test/MockMc.cpp index cf87e8704..bf31a0c4b 100644 --- a/mcrouter/lib/network/test/MockMc.cpp +++ b/mcrouter/lib/network/test/MockMc.cpp @@ -245,6 +245,10 @@ MockMc::findUnexpired(folly::StringPiece key) { return it; } +size_t MockMc::itemCount() const noexcept { + return citems_.size(); +} + void MockMc::flushAll() { citems_.clear(); } diff --git a/mcrouter/lib/network/test/MockMc.h b/mcrouter/lib/network/test/MockMc.h index 8d35019ef..52ecaea25 100644 --- a/mcrouter/lib/network/test/MockMc.h +++ b/mcrouter/lib/network/test/MockMc.h @@ -146,6 +146,8 @@ class MockMc { CasResult cas(folly::StringPiece key, Item item, uint64_t token); + size_t itemCount() const noexcept; + /** * clear all items */ diff --git a/mcrouter/lib/network/test/MockMcOnRequest.h b/mcrouter/lib/network/test/MockMcOnRequest.h index ba24c08eb..573401c33 100644 --- a/mcrouter/lib/network/test/MockMcOnRequest.h +++ b/mcrouter/lib/network/test/MockMcOnRequest.h @@ -355,6 +355,7 @@ class MockMcOnRequest { if (key == "__mockmc__") { StatsReply stats; stats.addStat("cmd_get_count", cmd_get_count.load()); + stats.addStat("total_items", mc_.itemCount()); Context::reply(std::move(ctx), stats.getReply()); } else { Context::reply(std::move(ctx), Reply(carbon::Result::BAD_COMMAND)); diff --git a/mcrouter/lib/network/test/TestClientServerUtil.cpp b/mcrouter/lib/network/test/TestClientServerUtil.cpp index 5722a1457..e09b8445f 100644 --- a/mcrouter/lib/network/test/TestClientServerUtil.cpp +++ b/mcrouter/lib/network/test/TestClientServerUtil.cpp @@ -87,6 +87,8 @@ void TestServerOnRequest::onRequest( processReply(std::move(ctx), Reply(carbon::Result::NOTFOUND)); } else if (req.key_ref()->fullKey() == "shutdown") { shutdownLock_.post(); + // TODO + std::this_thread::sleep_for(std::chrono::milliseconds(100)); processReply(std::move(ctx), Reply(carbon::Result::NOTFOUND)); flushQueue(); } else if (req.key_ref()->fullKey() == "busy") { diff --git a/mcrouter/test/MCProcess.py b/mcrouter/test/MCProcess.py index 5ba44938e..91c40029b 100644 --- a/mcrouter/test/MCProcess.py +++ b/mcrouter/test/MCProcess.py @@ -591,7 +591,6 @@ def stats(self, spec=None): if spec: q = "stats {spec}\r\n".format(spec=spec) self._sendall(q) - s = {} line = None fds = select.select([self.fd], [], [], 20.0) @@ -1030,7 +1029,8 @@ def __init__(self, port=None, ssl_port=None, extra_args=None): pass_fds = [] # if mockmc is used here, we initialize the same way as MockMemcached - if McrouterGlobals.binPath("mockmc") == args[0]: + self.is_mock_server = McrouterGlobals.binPath("mockmc") == args[0] + if self.is_mock_server: if port is None: listen_sock = create_listen_socket() port = listen_sock.getsockname()[1] @@ -1103,6 +1103,11 @@ def __init__(self, port=None, ssl_port=None, extra_args=None): tries -= 1 self.disconnect() + def stats(self, spec=None): + if self.is_mock_server: + return super().stats('__mockmc__') + return super().stats(spec) + def getsslport(self): return self.ssl_port diff --git a/mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp b/mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp index f655bfefa..1384b19e5 100644 --- a/mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp +++ b/mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp @@ -116,6 +116,7 @@ TEST(CarbonRouterClient, basicUsageSameThreadClient) { // gracefully. This ensures graceful destruction of the static // CarbonRouterInstance instance. router->shutdown(); + ioThreadPool->join(); ioThreadPool.reset(); EXPECT_TRUE(replyReceived); } diff --git a/mcrouter/test/test_unknown_name_handle.json b/mcrouter/test/test_unknown_name_handle.json index 7037b0b4f..798265aab 100644 --- a/mcrouter/test/test_unknown_name_handle.json +++ b/mcrouter/test/test_unknown_name_handle.json @@ -1,32 +1,32 @@ { + "pools": { + "A": { "servers": ["localhost:12345"] }, + "B": { "servers": ["localhost:12346"] } + }, "named_handles": [ { - "hash": { - "salt": "gut.texas" - }, - "name" : "B", - "pool": { - "name" : "B4", - "inherit" : "smc:twmemcache.gut.texas", - "protocol": "thrift", - "security_mech": "tls_to_plain", - "port_override": 11322, - "port_override_cross_dc": 11322, - "qos": { - "class": 2, - "path": 2 - }, - "port_override_within_dc": 11322 - }, - "type": "PoolRoute" + "type": "PoolRoute", + "name": "route:A", + "pool": "A" + }, + { + "type": "PoolRoute", + "name": "route:B", + "pool": "B" + }, + { + "type": "AllSyncRoute", + "name": "route:C", + "children": "NullRoute" + }, + { + "type": "AllSyncRoute", + "name": "route:all", + "children": ["route:A", "route:B", "route:C"] } ], - "route": { "type": "FailoverRoute", - "children": [ - "D", - "B" - ] + "children": ["D", "B"] } }