aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/grpc/client/ut/grpc_client_low_ut.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/grpc/client/ut/grpc_client_low_ut.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/grpc/client/ut/grpc_client_low_ut.cpp')
-rw-r--r--library/cpp/grpc/client/ut/grpc_client_low_ut.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/library/cpp/grpc/client/ut/grpc_client_low_ut.cpp b/library/cpp/grpc/client/ut/grpc_client_low_ut.cpp
new file mode 100644
index 0000000000..b8af2a518f
--- /dev/null
+++ b/library/cpp/grpc/client/ut/grpc_client_low_ut.cpp
@@ -0,0 +1,61 @@
+#include <library/cpp/grpc/client/grpc_client_low.h>
+
+#include <library/cpp/testing/unittest/registar.h>
+
+using namespace NGrpc;
+
+class TTestStub {
+public:
+ std::shared_ptr<grpc::ChannelInterface> ChannelInterface;
+ TTestStub(std::shared_ptr<grpc::ChannelInterface> channelInterface)
+ : ChannelInterface(channelInterface)
+ {}
+};
+
+Y_UNIT_TEST_SUITE(ChannelPoolTests) {
+ Y_UNIT_TEST(UnusedStubsHoldersDeletion) {
+ TGRpcClientConfig clientConfig("invalid_host:invalid_port");
+ TTcpKeepAliveSettings tcpKeepAliveSettings =
+ {
+ true,
+ 30, // NYdb::TCP_KEEPALIVE_IDLE, unused in UT, but is necessary in constructor
+ 5, // NYdb::TCP_KEEPALIVE_COUNT, unused in UT, but is necessary in constructor
+ 10 // NYdb::TCP_KEEPALIVE_INTERVAL, unused in UT, but is necessary in constructor
+ };
+ auto channelPool = TChannelPool(tcpKeepAliveSettings, TDuration::MilliSeconds(250));
+ std::vector<std::weak_ptr<grpc::ChannelInterface>> ChannelInterfacesWeak;
+
+ {
+ std::vector<std::shared_ptr<TTestStub>> stubsHoldersShared;
+ auto storeStubsHolders = [&](TStubsHolder& stubsHolder) {
+ stubsHoldersShared.emplace_back(stubsHolder.GetOrCreateStub<TTestStub>());
+ ChannelInterfacesWeak.emplace_back((*stubsHoldersShared.rbegin())->ChannelInterface);
+ return;
+ };
+ for (int i = 0; i < 10; ++i) {
+ channelPool.GetStubsHolderLocked(
+ ToString(i),
+ clientConfig,
+ storeStubsHolders
+ );
+ }
+ }
+
+ auto now = Now();
+ while (Now() < now + TDuration::MilliSeconds(500)){
+ Sleep(TDuration::MilliSeconds(100));
+ }
+
+ channelPool.DeleteExpiredStubsHolders();
+
+ bool allDeleted = true;
+ for (auto i = ChannelInterfacesWeak.begin(); i != ChannelInterfacesWeak.end(); ++i) {
+ allDeleted = allDeleted && i->expired();
+ }
+
+ // assertion is made for channel interfaces instead of stubs, because after stub deletion
+ // TStubsHolder has the only shared_ptr for channel interface.
+ UNIT_ASSERT_C(allDeleted, "expired stubsHolders were not deleted after timeout");
+
+ }
+} // ChannelPoolTests ut suite \ No newline at end of file