aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2023-08-21 14:10:46 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2023-08-21 15:29:54 +0300
commit4220b24de1e83ff216e98cbb451f34b2871b4a91 (patch)
treeca25f365fe3857346a60253943bf7e6ea89bed65 /library/cpp
parent69809b16c83fab8124e9dd87c284b57c694e1f49 (diff)
downloadydb-4220b24de1e83ff216e98cbb451f34b2871b4a91.tar.gz
Intermediate changes
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/http/server/http_ut.cpp50
1 files changed, 49 insertions, 1 deletions
diff --git a/library/cpp/http/server/http_ut.cpp b/library/cpp/http/server/http_ut.cpp
index ecebca5a2b..a74e31c37e 100644
--- a/library/cpp/http/server/http_ut.cpp
+++ b/library/cpp/http/server/http_ut.cpp
@@ -9,6 +9,7 @@
#include <util/stream/zlib.h>
#include <util/system/datetime.h>
#include <util/system/mutex.h>
+#include <util/random/random.h>
Y_UNIT_TEST_SUITE(THttpServerTest) {
class TEchoServer: public THttpServer::ICallBack {
@@ -763,16 +764,19 @@ Y_UNIT_TEST_SUITE(THttpServerTest) {
try {
TTestRequest r(port);
r.KeepAliveConnection = true;
- for (;;) {
+ for (size_t j = 0; j < 100; ++j) {
if (Stopped_.load()) {
return;
}
r.Execute();
+ Sleep(TDuration::MilliSeconds(1) * RandomNumber<float>());
Counters_[i].Success++;
}
} catch (TSystemError& e) {
UNIT_ASSERT_C(e.Status() == ECONNRESET || e.Status() == ECONNREFUSED, CurrentExceptionMessage());
Counters_[i].Fail++;
+ } catch (THttpReadException&) {
+ Counters_[i].Fail++;
} catch (...) {
UNIT_ASSERT_C(false, CurrentExceptionMessage());
}
@@ -854,6 +858,50 @@ Y_UNIT_TEST_SUITE(THttpServerTest) {
}
}
}
+ }
+
+ Y_UNIT_TEST(TestMaxConnections) {
+ class TMaxConnServer
+ : public TEchoServer
+ {
+ public:
+ using TEchoServer::TEchoServer;
+
+ void OnMaxConn() override {
+ ++MaxConns;
+ }
+ public:
+ std::atomic<size_t> MaxConns = 0;
+
+ };
+
+ TPortManager pm;
+ const ui16 port = pm.GetPort();
+
+ const size_t maxConnections = 5;
+ TString res = TestData();
+ TMaxConnServer serverImpl(res);
+ THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).SetMaxConnections(maxConnections));
+
+ UNIT_ASSERT(server.Start());
+
+ TShooter shooter(maxConnections + 1, port);
+
+ for (size_t i = 0; i < 100; ++i) {
+ const size_t prev = serverImpl.MaxConns.load();
+ while (serverImpl.MaxConns.load() < prev + 100) {
+ Sleep(TDuration::MilliSeconds(1));
+ }
+ }
+
+ shooter.Stop();
+ server.Stop();
+
+ for (const auto& c : shooter.GetCounters()) {
+ UNIT_ASSERT(c.Success > 0);
+ UNIT_ASSERT(c.Fail > 0);
+ UNIT_ASSERT(c.Success > c.Fail);
+ }
}
}