From 4a0f06193b74e7b0698115d76711acb8c5e9fc65 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sun, 1 Sep 2019 11:10:27 -0700 Subject: [PATCH] refactoring --- ws/ws_autobahn.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/ws/ws_autobahn.cpp b/ws/ws_autobahn.cpp index c92bedcd..5030e874 100644 --- a/ws/ws_autobahn.cpp +++ b/ws/ws_autobahn.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -130,19 +131,61 @@ namespace ix _webSocket.stop(); } + void generateReport(const std::string& url) + { + ix::WebSocket webSocket; + std::string reportUrl(url); + reportUrl += "/updateReports?agent=ixwebsocket"; + webSocket.setUrl(reportUrl); + webSocket.disableAutomaticReconnection(); + + std::atomic done(false); + webSocket.setOnMessageCallback( + [&done](const ix::WebSocketMessagePtr& msg) + { + if (msg->type == ix::WebSocketMessageType::Close) + { + std::cerr << "Report generated" << std::endl; + 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; + } + } + ); + webSocket.start(); + + while (!done) + { + std::chrono::duration duration(10); + std::this_thread::sleep_for(duration); + } + + webSocket.stop(); + } + // - // make && bench ws autobahn --url 'ws://localhost:9001/runCase?case=9&agent=ixwebsocket' && ws connect -d 'ws://localhost:9001/updateReports?agent=ixwebsocket' + // make && bench ws autobahn --url ws://localhost:9001 // int ws_autobahn_main(const std::string& url, bool quiet) { - int N = 1; // 519; + int N = 519; N++; for (int i = 1 ; i < N; ++i) { + std::cerr << "Execute test case " << i << std::endl; + int caseNumber = i; std::stringstream ss; - ss << "ws://localhost:9001/runCase?case=" + ss << url + << "/runCase?case=" << caseNumber << "&agent=ixwebsocket"; @@ -152,6 +195,8 @@ namespace ix testCase.run(); } + generateReport(url); + return 0; } }