MCPcopy Create free account
hub / github.com/catboost/catboost / CreateServices

Function CreateServices

library/cpp/neh/http_ut.cpp:59–91  ·  view source on GitHub ↗

Creates service for serving request. @return ptr to IServices, port and error if occured. Tests failes if server could not be created. */

Source from the content-addressed store, hash-verified

57 @return ptr to IServices, port and error if occured. Tests failes if server could not be created.
58 */
59 TServ CreateServices(const TServiceFunction& f =
60 [](const IRequestRef& req) {
61 TDataSaver responseData;
62 Sleep(TDuration::MilliSeconds(FromString<int>(req->Data())));
63 responseData << req->Data();
64 auto* httpReq = dynamic_cast<IHttpRequest*>(req.Get());
65 TString headers = "\r\nContent-Type: text/plain";
66 httpReq->SendReply(responseData, headers);
67 }
68 ) {
69 TServ serv;
70 TString err;
71
72 //in loop try run service (bind port)
73 for (ui16 basePort = 20000; basePort < 40000; basePort += 100) {
74 serv.Services = CreateLoop();
75 try {
76 serv.ServerPort = basePort;
77 TStringStream addr;
78 addr << "http://localhost:" << serv.ServerPort << "/pipeline";
79
80 serv.Services->Add(addr.Str(), f);
81 serv.Services->ForkLoop(16); //<< throw exception, if can not bind port
82 break;
83 } catch (...) {
84 serv.Services.Destroy();
85 err = CurrentExceptionMessage();
86 }
87 }
88
89 UNIT_ASSERT_C(serv.Services.Get(), err.data());
90 return serv;
91 }
92
93 TString Request(SOCKET s, const TString& request) {
94 const ssize_t nSend = send(s, request.data(), request.size(), 0);

Callers 1

Y_UNIT_TESTFunction · 0.70

Calls 11

SleepFunction · 0.85
MilliSecondsFunction · 0.85
CurrentExceptionMessageFunction · 0.85
DataMethod · 0.45
GetMethod · 0.45
SendReplyMethod · 0.45
AddMethod · 0.45
StrMethod · 0.45
ForkLoopMethod · 0.45
DestroyMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected