From 730fbc5b3102de283585ce87f809ec37c88824fc Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Mon, 26 Oct 2020 19:18:55 -0700 Subject: [PATCH] unity build fixes --- CMakeLists.txt | 3 ++- makefile | 3 +++ test/IXCobraToSentryBotTest.cpp | 29 --------------------------- test/IXCobraToStatsdBotTest.cpp | 32 ------------------------------ test/IXCobraToStdoutBotTest.cpp | 33 ------------------------------- test/IXTest.cpp | 31 +++++++++++++++++++++++++++++ test/IXTest.h | 3 +++ test/IXWebSocketBroadcastTest.cpp | 28 +++++++++++++------------- 8 files changed, 53 insertions(+), 109 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce3b4a25..ef5e3bdd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,7 +264,8 @@ if (USE_WS OR USE_TEST) include(FetchContent) FetchContent_Declare(spdlog GIT_REPOSITORY "https://github.com/gabime/spdlog" - GIT_TAG "v1.8.0") + GIT_TAG "v1.8.0" + GIT_SHALLOW 1) FetchContent_MakeAvailable(spdlog) diff --git a/makefile b/makefile index b61f0dc8..53bf9a3a 100644 --- a/makefile +++ b/makefile @@ -33,6 +33,9 @@ ws_mbedtls_install: ws: mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_WS=1 .. && ninja install) +ws_unity: + mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_UNITY_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_WS=1 .. && ninja install) + ws_install: mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=MinSizeRel -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_WS=1 .. -DUSE_TEST=0 && ninja install) diff --git a/test/IXCobraToSentryBotTest.cpp b/test/IXCobraToSentryBotTest.cpp index 7a64d747..36408ca0 100644 --- a/test/IXCobraToSentryBotTest.cpp +++ b/test/IXCobraToSentryBotTest.cpp @@ -38,35 +38,6 @@ namespace } }); } - - void runPublisher(const ix::CobraConfig& config, const std::string& channel) - { - ix::CobraMetricsPublisher cobraMetricsPublisher; - cobraMetricsPublisher.configure(config, channel); - cobraMetricsPublisher.setSession(uuid4()); - cobraMetricsPublisher.enable(true); - - Json::Value msg; - msg["fps"] = 60; - - cobraMetricsPublisher.setGenericAttributes("game", "ody"); - - // Wait a bit - ix::msleep(500); - - // publish some messages - cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #1) - cobraMetricsPublisher.push("sms_metric_B_id", msg); // (msg #2) - ix::msleep(500); - - cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #3) - cobraMetricsPublisher.push("sms_metric_D_id", msg); // (msg #4) - ix::msleep(500); - - cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #4) - cobraMetricsPublisher.push("sms_metric_F_id", msg); // (msg #5) - ix::msleep(500); - } } // namespace TEST_CASE("Cobra_to_sentry_bot", "[cobra_bots]") diff --git a/test/IXCobraToStatsdBotTest.cpp b/test/IXCobraToStatsdBotTest.cpp index 67db5928..db198a48 100644 --- a/test/IXCobraToStatsdBotTest.cpp +++ b/test/IXCobraToStatsdBotTest.cpp @@ -20,38 +20,6 @@ using namespace ix; -namespace -{ - void runPublisher(const ix::CobraConfig& config, const std::string& channel) - { - ix::CobraMetricsPublisher cobraMetricsPublisher; - cobraMetricsPublisher.configure(config, channel); - cobraMetricsPublisher.setSession(uuid4()); - cobraMetricsPublisher.enable(true); - - Json::Value msg; - msg["fps"] = 60; - - cobraMetricsPublisher.setGenericAttributes("game", "ody"); - - // Wait a bit - ix::msleep(500); - - // publish some messages - cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #1) - cobraMetricsPublisher.push("sms_metric_B_id", msg); // (msg #2) - ix::msleep(500); - - cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #3) - cobraMetricsPublisher.push("sms_metric_D_id", msg); // (msg #4) - ix::msleep(500); - - cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #4) - cobraMetricsPublisher.push("sms_metric_F_id", msg); // (msg #5) - ix::msleep(500); - } -} // namespace - TEST_CASE("Cobra_to_statsd_bot", "[cobra_bots]") { SECTION("Exchange and count sent/received messages.") diff --git a/test/IXCobraToStdoutBotTest.cpp b/test/IXCobraToStdoutBotTest.cpp index 4b864206..6746f717 100644 --- a/test/IXCobraToStdoutBotTest.cpp +++ b/test/IXCobraToStdoutBotTest.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -20,38 +19,6 @@ using namespace ix; -namespace -{ - void runPublisher(const ix::CobraConfig& config, const std::string& channel) - { - ix::CobraMetricsPublisher cobraMetricsPublisher; - cobraMetricsPublisher.configure(config, channel); - cobraMetricsPublisher.setSession(uuid4()); - cobraMetricsPublisher.enable(true); - - Json::Value msg; - msg["fps"] = 60; - - cobraMetricsPublisher.setGenericAttributes("game", "ody"); - - // Wait a bit - ix::msleep(500); - - // publish some messages - cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #1) - cobraMetricsPublisher.push("sms_metric_B_id", msg); // (msg #2) - ix::msleep(500); - - cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #3) - cobraMetricsPublisher.push("sms_metric_D_id", msg); // (msg #4) - ix::msleep(500); - - cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #4) - cobraMetricsPublisher.push("sms_metric_F_id", msg); // (msg #5) - ix::msleep(500); - } -} // namespace - TEST_CASE("Cobra_to_stdout_bot", "[cobra_bots]") { SECTION("Exchange and count sent/received messages.") diff --git a/test/IXTest.cpp b/test/IXTest.cpp index 0961751b..ae289d68 100644 --- a/test/IXTest.cpp +++ b/test/IXTest.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -243,4 +245,33 @@ namespace ix return endpoint; } + + void runPublisher(const ix::CobraConfig& config, const std::string& channel) + { + ix::CobraMetricsPublisher cobraMetricsPublisher; + cobraMetricsPublisher.configure(config, channel); + cobraMetricsPublisher.setSession(uuid4()); + cobraMetricsPublisher.enable(true); + + Json::Value msg; + msg["fps"] = 60; + + cobraMetricsPublisher.setGenericAttributes("game", "ody"); + + // Wait a bit + ix::msleep(500); + + // publish some messages + cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #1) + cobraMetricsPublisher.push("sms_metric_B_id", msg); // (msg #2) + ix::msleep(500); + + cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #3) + cobraMetricsPublisher.push("sms_metric_D_id", msg); // (msg #4) + ix::msleep(500); + + cobraMetricsPublisher.push("sms_metric_A_id", msg); // (msg #4) + cobraMetricsPublisher.push("sms_metric_F_id", msg); // (msg #5) + ix::msleep(500); + } } // namespace ix diff --git a/test/IXTest.h b/test/IXTest.h index b7c68a27..6f9e394b 100644 --- a/test/IXTest.h +++ b/test/IXTest.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -59,4 +60,6 @@ namespace ix std::string getWsScheme(bool preferTLS); std::string makeCobraEndpoint(int port, bool preferTLS); + + void runPublisher(const ix::CobraConfig& config, const std::string& channel); } // namespace ix diff --git a/test/IXWebSocketBroadcastTest.cpp b/test/IXWebSocketBroadcastTest.cpp index 0c8d449a..fcabcb82 100644 --- a/test/IXWebSocketBroadcastTest.cpp +++ b/test/IXWebSocketBroadcastTest.cpp @@ -18,10 +18,10 @@ using namespace ix; namespace { - class WebSocketChat + class WebSocketBroadcastChat { public: - WebSocketChat(const std::string& user, const std::string& session, int port); + WebSocketBroadcastChat(const std::string& user, const std::string& session, int port); void subscribe(const std::string& channel); void start(); @@ -47,7 +47,7 @@ namespace mutable std::mutex _mutex; }; - WebSocketChat::WebSocketChat(const std::string& user, const std::string& session, int port) + WebSocketBroadcastChat::WebSocketBroadcastChat(const std::string& user, const std::string& session, int port) : _user(user) , _session(session) , _port(port) @@ -55,35 +55,35 @@ namespace _webSocket.setTLSOptions(makeClientTLSOptions()); } - size_t WebSocketChat::getReceivedMessagesCount() const + size_t WebSocketBroadcastChat::getReceivedMessagesCount() const { std::lock_guard lock(_mutex); return _receivedMessages.size(); } - const std::vector& WebSocketChat::getReceivedMessages() const + const std::vector& WebSocketBroadcastChat::getReceivedMessages() const { std::lock_guard lock(_mutex); return _receivedMessages; } - void WebSocketChat::appendMessage(const std::string& message) + void WebSocketBroadcastChat::appendMessage(const std::string& message) { std::lock_guard lock(_mutex); _receivedMessages.push_back(message); } - bool WebSocketChat::isReady() const + bool WebSocketBroadcastChat::isReady() const { return _webSocket.getReadyState() == ix::ReadyState::Open; } - void WebSocketChat::stop() + void WebSocketBroadcastChat::stop() { _webSocket.stop(); } - void WebSocketChat::start() + void WebSocketBroadcastChat::start() { std::string url; { @@ -156,7 +156,7 @@ namespace _webSocket.start(); } - std::pair WebSocketChat::decodeMessage(const std::string& str) + std::pair WebSocketBroadcastChat::decodeMessage(const std::string& str) { std::string errMsg; MsgPack msg = MsgPack::parse(str, errMsg); @@ -167,7 +167,7 @@ namespace return std::pair(msg_user, msg_text); } - std::string WebSocketChat::encodeMessage(const std::string& text) + std::string WebSocketBroadcastChat::encodeMessage(const std::string& text) { std::map obj; obj["user"] = _user; @@ -179,7 +179,7 @@ namespace return output; } - void WebSocketChat::sendMessage(const std::string& text) + void WebSocketBroadcastChat::sendMessage(const std::string& text) { _webSocket.sendBinary(encodeMessage(text)); } @@ -248,11 +248,11 @@ TEST_CASE("Websocket_broadcast_server", "[websocket_server]") REQUIRE(startServer(server, connectionId)); std::string session = ix::generateSessionId(); - std::vector> chatClients; + std::vector> chatClients; for (int i = 0; i < 10; ++i) { std::string user("user_" + std::to_string(i)); - chatClients.push_back(std::make_shared(user, session, port)); + chatClients.push_back(std::make_shared(user, session, port)); chatClients[i]->start(); ix::msleep(50); }