From 61bd76578424dd40ca46ed08652bd349b1b6b8c5 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sun, 1 Sep 2019 11:17:28 -0700 Subject: [PATCH] compute test case count properly --- ws/ws_autobahn.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/ws/ws_autobahn.cpp b/ws/ws_autobahn.cpp index 5030e874..137e05b8 100644 --- a/ws/ws_autobahn.cpp +++ b/ws/ws_autobahn.cpp @@ -170,13 +170,63 @@ namespace ix webSocket.stop(); } + int getTestCaseCount(const std::string& url) + { + ix::WebSocket webSocket; + std::string caseCountUrl(url); + caseCountUrl += "/getCaseCount"; + webSocket.setUrl(caseCountUrl); + webSocket.disableAutomaticReconnection(); + + int count = 0; + + std::atomic done(false); + webSocket.setOnMessageCallback( + [&done, &count](const ix::WebSocketMessagePtr& msg) + { + if (msg->type == ix::WebSocketMessageType::Close) + { + done = true; + } + else if (msg->type == ix::WebSocketMessageType::Error) + { + std::stringstream ss; + ss << "Connection error: " << msg->errorInfo.reason << std::endl; + ss << "#retries: " << msg->errorInfo.retries << std::endl; + ss << "Wait time(ms): " << msg->errorInfo.wait_time << std::endl; + ss << "HTTP Status: " << msg->errorInfo.http_status << std::endl; + std::cerr << ss.str() << std::endl; + } + else if (msg->type == ix::WebSocketMessageType::Message) + { + // response is a string + std::stringstream ss; + ss << msg->str; + ss >> count; + } + } + ); + webSocket.start(); + + while (!done) + { + std::chrono::duration duration(10); + std::this_thread::sleep_for(duration); + } + + webSocket.stop(); + + return count; + } + // // make && bench ws autobahn --url ws://localhost:9001 // int ws_autobahn_main(const std::string& url, bool quiet) { - int N = 519; + int N = getTestCaseCount(url); N++; + for (int i = 1 ; i < N; ++i) { std::cerr << "Execute test case " << i << std::endl;