16std::shared_ptr<ROOT::Experimental::RWebWindow> window;
19bool window_terminated =
false;
21bool batch_mode =
false;
22int current_counter = 0;
24auto start_tm = std::chrono::high_resolution_clock::now();
25auto firstmsg_tm = start_tm;
26auto stop_tm = start_tm;
27std::string round_trip =
"<not defined>";
29void ProcessData(
unsigned connid,
const std::string &arg)
31 if (arg.find(
"PING:") == 0) {
32 window->Send(connid, arg);
33 }
else if (arg ==
"first") {
35 firstmsg_tm = std::chrono::high_resolution_clock::now();
36 window->Send(connid, std::string(
"CLIENTS:") + std::to_string(num_clients));
37 }
else if (arg.find(
"SHOW:") == 0) {
38 std::string msg = arg.substr(5);
40 std::cout << msg << std::endl;
41 if (msg.find(
"Cnt:") == 0) {
42 int counter = std::stoi(msg.substr(4));
44 current_counter = counter;
47 auto p = msg.find(
"round-trip:");
48 if (p > 0) round_trip = msg.substr(p);
50 }
else if (arg ==
"halt") {
52 window_terminated =
true;
53 window->TerminateROOT();
71 modeHttpWindowThread = 3,
80void ping(
int nclients = 1,
int test_mode = 0)
82 num_clients = nclients;
84 batch_mode =
gROOT->IsBatch();
87 if (test_mode < 0) test_mode = 0;
88 int major_mode = test_mode / 10;
89 test_mode = test_mode % 10;
90 if (test_mode > modeCivetThread)
91 test_mode = modeDefault;
95 else if (num_clients > 1000)
99 if (major_mode == majorLongpoll)
106 if ((test_mode == modeHttpThread) || (test_mode == modeHttpWindowThread))
110 if (test_mode == modeMinimalTimer)
121 window->SetConnLimit(num_clients);
126 std::string fname = __FILE__;
127 auto pos = fname.find(
"ping.cxx");
128 if (pos > 0) { fname.resize(pos); fname.append(
"ping.html"); }
129 else fname =
"ping.html";
130 window->SetDefaultPage(std::string(
"file:") + fname);
133 window->SetGeometry(300, 500);
137 window->SetDataCallBack(ProcessData);
140 if (test_mode == modeCivetThread)
141 window->UseServerThreads();
143 if (test_mode == modeHttpWindowThread)
144 window->StartThread();
148 window->Show(batch_mode ?
"headless" :
"");
150 std::cout <<
"Window url is: " << window->GetUrl(
true) << std::endl;
154 const int run_limit = 200;
155 const double fullrun_time = 100., startup_time = 70.;
156 start_tm = firstmsg_tm = std::chrono::high_resolution_clock::now();
157 window->WaitFor([=](
double tm) {
return (current_counter >= run_limit) || (tm > fullrun_time) || ((current_counter == 0) && (tm > startup_time)) ? 1 : 0; });
158 stop_tm = std::chrono::high_resolution_clock::now();
159 auto startuptime_int = std::chrono::duration_cast<std::chrono::milliseconds>(firstmsg_tm - start_tm);
160 auto runttime_int = std::chrono::duration_cast<std::chrono::milliseconds>(stop_tm - firstmsg_tm);
162 if (current_counter >= run_limit)
163 std::cout <<
"PING-PONG TEST COMPLETED " << round_trip;
165 std::cout <<
"PING-PONG TEST FAIL cnt:" << current_counter;
167 std::cout <<
" startup: " << startuptime_int.count() <<
"ms" <<
" run: " << runttime_int.count() <<
"ms" << std::endl;
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
Set the value of a resource or create a new resource.