unity build fixes

This commit is contained in:
Benjamin Sergeant 2020-10-26 19:18:55 -07:00
parent d0562664ad
commit 730fbc5b31
8 changed files with 53 additions and 109 deletions

View File

@ -264,7 +264,8 @@ if (USE_WS OR USE_TEST)
include(FetchContent) include(FetchContent)
FetchContent_Declare(spdlog FetchContent_Declare(spdlog
GIT_REPOSITORY "https://github.com/gabime/spdlog" GIT_REPOSITORY "https://github.com/gabime/spdlog"
GIT_TAG "v1.8.0") GIT_TAG "v1.8.0"
GIT_SHALLOW 1)
FetchContent_MakeAvailable(spdlog) FetchContent_MakeAvailable(spdlog)

View File

@ -33,6 +33,9 @@ ws_mbedtls_install:
ws: ws:
mkdir -p build && (cd build ; cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHON=1 -DUSE_TLS=1 -DUSE_WS=1 .. && ninja install) 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: 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) 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)

View File

@ -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 } // namespace
TEST_CASE("Cobra_to_sentry_bot", "[cobra_bots]") TEST_CASE("Cobra_to_sentry_bot", "[cobra_bots]")

View File

@ -20,38 +20,6 @@
using namespace ix; 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]") TEST_CASE("Cobra_to_statsd_bot", "[cobra_bots]")
{ {
SECTION("Exchange and count sent/received messages.") SECTION("Exchange and count sent/received messages.")

View File

@ -10,7 +10,6 @@
#include <iostream> #include <iostream>
#include <ixbots/IXCobraToStdoutBot.h> #include <ixbots/IXCobraToStdoutBot.h>
#include <ixcobra/IXCobraConnection.h> #include <ixcobra/IXCobraConnection.h>
#include <ixcobra/IXCobraMetricsPublisher.h>
#include <ixcrypto/IXUuid.h> #include <ixcrypto/IXUuid.h>
#include <ixredis/IXRedisServer.h> #include <ixredis/IXRedisServer.h>
#include <ixsentry/IXSentryClient.h> #include <ixsentry/IXSentryClient.h>
@ -20,38 +19,6 @@
using namespace ix; 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]") TEST_CASE("Cobra_to_stdout_bot", "[cobra_bots]")
{ {
SECTION("Exchange and count sent/received messages.") SECTION("Exchange and count sent/received messages.")

View File

@ -12,6 +12,8 @@
#include <iostream> #include <iostream>
#include <ixwebsocket/IXNetSystem.h> #include <ixwebsocket/IXNetSystem.h>
#include <ixwebsocket/IXWebSocket.h> #include <ixwebsocket/IXWebSocket.h>
#include <ixcobra/IXCobraMetricsPublisher.h>
#include <ixcrypto/IXUuid.h>
#include <mutex> #include <mutex>
#include <random> #include <random>
#include <stack> #include <stack>
@ -243,4 +245,33 @@ namespace ix
return endpoint; 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 } // namespace ix

View File

@ -8,6 +8,7 @@
#include <iostream> #include <iostream>
#include <ixsnake/IXAppConfig.h> #include <ixsnake/IXAppConfig.h>
#include <ixcobra/IXCobraConfig.h>
#include <ixwebsocket/IXGetFreePort.h> #include <ixwebsocket/IXGetFreePort.h>
#include <ixwebsocket/IXSocketTLSOptions.h> #include <ixwebsocket/IXSocketTLSOptions.h>
#include <ixwebsocket/IXWebSocketServer.h> #include <ixwebsocket/IXWebSocketServer.h>
@ -59,4 +60,6 @@ namespace ix
std::string getWsScheme(bool preferTLS); std::string getWsScheme(bool preferTLS);
std::string makeCobraEndpoint(int port, bool preferTLS); std::string makeCobraEndpoint(int port, bool preferTLS);
void runPublisher(const ix::CobraConfig& config, const std::string& channel);
} // namespace ix } // namespace ix

View File

@ -18,10 +18,10 @@ using namespace ix;
namespace namespace
{ {
class WebSocketChat class WebSocketBroadcastChat
{ {
public: 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 subscribe(const std::string& channel);
void start(); void start();
@ -47,7 +47,7 @@ namespace
mutable std::mutex _mutex; 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) : _user(user)
, _session(session) , _session(session)
, _port(port) , _port(port)
@ -55,35 +55,35 @@ namespace
_webSocket.setTLSOptions(makeClientTLSOptions()); _webSocket.setTLSOptions(makeClientTLSOptions());
} }
size_t WebSocketChat::getReceivedMessagesCount() const size_t WebSocketBroadcastChat::getReceivedMessagesCount() const
{ {
std::lock_guard<std::mutex> lock(_mutex); std::lock_guard<std::mutex> lock(_mutex);
return _receivedMessages.size(); return _receivedMessages.size();
} }
const std::vector<std::string>& WebSocketChat::getReceivedMessages() const const std::vector<std::string>& WebSocketBroadcastChat::getReceivedMessages() const
{ {
std::lock_guard<std::mutex> lock(_mutex); std::lock_guard<std::mutex> lock(_mutex);
return _receivedMessages; return _receivedMessages;
} }
void WebSocketChat::appendMessage(const std::string& message) void WebSocketBroadcastChat::appendMessage(const std::string& message)
{ {
std::lock_guard<std::mutex> lock(_mutex); std::lock_guard<std::mutex> lock(_mutex);
_receivedMessages.push_back(message); _receivedMessages.push_back(message);
} }
bool WebSocketChat::isReady() const bool WebSocketBroadcastChat::isReady() const
{ {
return _webSocket.getReadyState() == ix::ReadyState::Open; return _webSocket.getReadyState() == ix::ReadyState::Open;
} }
void WebSocketChat::stop() void WebSocketBroadcastChat::stop()
{ {
_webSocket.stop(); _webSocket.stop();
} }
void WebSocketChat::start() void WebSocketBroadcastChat::start()
{ {
std::string url; std::string url;
{ {
@ -156,7 +156,7 @@ namespace
_webSocket.start(); _webSocket.start();
} }
std::pair<std::string, std::string> WebSocketChat::decodeMessage(const std::string& str) std::pair<std::string, std::string> WebSocketBroadcastChat::decodeMessage(const std::string& str)
{ {
std::string errMsg; std::string errMsg;
MsgPack msg = MsgPack::parse(str, errMsg); MsgPack msg = MsgPack::parse(str, errMsg);
@ -167,7 +167,7 @@ namespace
return std::pair<std::string, std::string>(msg_user, msg_text); return std::pair<std::string, std::string>(msg_user, msg_text);
} }
std::string WebSocketChat::encodeMessage(const std::string& text) std::string WebSocketBroadcastChat::encodeMessage(const std::string& text)
{ {
std::map<MsgPack, MsgPack> obj; std::map<MsgPack, MsgPack> obj;
obj["user"] = _user; obj["user"] = _user;
@ -179,7 +179,7 @@ namespace
return output; return output;
} }
void WebSocketChat::sendMessage(const std::string& text) void WebSocketBroadcastChat::sendMessage(const std::string& text)
{ {
_webSocket.sendBinary(encodeMessage(text)); _webSocket.sendBinary(encodeMessage(text));
} }
@ -248,11 +248,11 @@ TEST_CASE("Websocket_broadcast_server", "[websocket_server]")
REQUIRE(startServer(server, connectionId)); REQUIRE(startServer(server, connectionId));
std::string session = ix::generateSessionId(); std::string session = ix::generateSessionId();
std::vector<std::shared_ptr<WebSocketChat>> chatClients; std::vector<std::shared_ptr<WebSocketBroadcastChat>> chatClients;
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
std::string user("user_" + std::to_string(i)); std::string user("user_" + std::to_string(i));
chatClients.push_back(std::make_shared<WebSocketChat>(user, session, port)); chatClients.push_back(std::make_shared<WebSocketBroadcastChat>(user, session, port));
chatClients[i]->start(); chatClients[i]->start();
ix::msleep(50); ix::msleep(50);
} }