wip / compile but unittest failures

This commit is contained in:
Benjamin Sergeant 2020-04-14 10:47:10 -07:00
parent 415f6b4832
commit cc588f9c05
13 changed files with 87 additions and 60 deletions

View File

@ -44,6 +44,7 @@ set( IXWEBSOCKET_SOURCES
ixwebsocket/IXWebSocketCloseConstants.cpp ixwebsocket/IXWebSocketCloseConstants.cpp
ixwebsocket/IXWebSocketHandshake.cpp ixwebsocket/IXWebSocketHandshake.cpp
ixwebsocket/IXWebSocketHttpHeaders.cpp ixwebsocket/IXWebSocketHttpHeaders.cpp
ixwebsocket/IXWebSocketMessage.cpp
ixwebsocket/IXWebSocketPerMessageDeflate.cpp ixwebsocket/IXWebSocketPerMessageDeflate.cpp
ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp
ixwebsocket/IXWebSocketPerMessageDeflateOptions.cpp ixwebsocket/IXWebSocketPerMessageDeflateOptions.cpp

View File

@ -30,16 +30,16 @@ namespace ix
, _handshakeTimeoutSecs(kDefaultHandShakeTimeoutSecs) , _handshakeTimeoutSecs(kDefaultHandShakeTimeoutSecs)
, _enablePong(kDefaultEnablePong) , _enablePong(kDefaultEnablePong)
, _pingIntervalSecs(kDefaultPingIntervalSecs) , _pingIntervalSecs(kDefaultPingIntervalSecs)
, _webSocketMessage(std::make_unique<WebSocketMessage>(WebSocketMessageType::Message))
, _webSocketErrorMessage(std::make_unique<WebSocketMessage>(WebSocketMessageType::Error))
, _webSocketOpenMessage(std::make_unique<WebSocketMessage>(WebSocketMessageType::Open))
, _webSocketCloseMessage(std::make_unique<WebSocketMessage>(WebSocketMessageType::Close))
{ {
_ws.setOnCloseCallback( _ws.setOnCloseCallback(
[this](uint16_t code, const std::string& reason, size_t wireSize, bool remote) { [this](uint16_t code, const std::string& reason, size_t wireSize, bool remote) {
_onMessageCallback( _webSocketCloseMessage->wireSize = wireSize;
std::make_unique<WebSocketMessage>(WebSocketMessageType::Close, _webSocketCloseMessage->closeInfo = WebSocketCloseInfo(code, reason, remote);
"", _onMessageCallback(_webSocketCloseMessage);
wireSize,
WebSocketErrorInfo(),
WebSocketOpenInfo(),
WebSocketCloseInfo(code, reason, remote)));
}); });
} }
@ -193,13 +193,8 @@ namespace ix
return status; return status;
} }
_onMessageCallback(std::make_unique<WebSocketMessage>( _webSocketOpenMessage->openInfo = WebSocketOpenInfo(status.uri, status.headers, status.protocol),
WebSocketMessageType::Open, _onMessageCallback(_webSocketOpenMessage);
"",
0,
WebSocketErrorInfo(),
WebSocketOpenInfo(status.uri, status.headers, status.protocol),
WebSocketCloseInfo()));
if (_pingIntervalSecs > 0) if (_pingIntervalSecs > 0)
{ {
@ -224,13 +219,8 @@ namespace ix
return status; return status;
} }
_onMessageCallback( _webSocketOpenMessage->openInfo = WebSocketOpenInfo(status.uri, status.headers);
std::make_unique<WebSocketMessage>(WebSocketMessageType::Open, _onMessageCallback(_webSocketOpenMessage);
"",
0,
WebSocketErrorInfo(),
WebSocketOpenInfo(status.uri, status.headers),
WebSocketCloseInfo()));
if (_pingIntervalSecs > 0) if (_pingIntervalSecs > 0)
{ {
@ -310,12 +300,8 @@ namespace ix
connectErr.reason = status.errorStr; connectErr.reason = status.errorStr;
connectErr.http_status = status.http_status; connectErr.http_status = status.http_status;
_onMessageCallback(std::make_unique<WebSocketMessage>(WebSocketMessageType::Error, _webSocketErrorMessage->errorInfo = connectErr;
"", _onMessageCallback(_webSocketErrorMessage);
0,
connectErr,
WebSocketOpenInfo(),
WebSocketCloseInfo()));
} }
} }
} }
@ -381,18 +367,15 @@ namespace ix
break; break;
} }
WebSocketErrorInfo webSocketErrorInfo;
webSocketErrorInfo.decompressionError = decompressionError;
bool binary = messageKind == WebSocketTransport::MessageKind::MSG_BINARY; bool binary = messageKind == WebSocketTransport::MessageKind::MSG_BINARY;
_onMessageCallback(std::make_unique<WebSocketMessage>(webSocketMessageType, _webSocketMessage->type = webSocketMessageType;
msg, _webSocketMessage->str = msg;
wireSize, _webSocketMessage->wireSize = wireSize;
webSocketErrorInfo, _webSocketMessage->errorInfo.decompressionError = decompressionError;
WebSocketOpenInfo(), _webSocketMessage->binary = binary;
WebSocketCloseInfo(),
binary)); _onMessageCallback(_webSocketMessage);
WebSocket::invokeTrafficTrackerCallback(wireSize, true); WebSocket::invokeTrafficTrackerCallback(wireSize, true);
}); });

View File

@ -155,6 +155,12 @@ namespace ix
static const int kDefaultPingIntervalSecs; static const int kDefaultPingIntervalSecs;
static const int kDefaultPingTimeoutSecs; static const int kDefaultPingTimeoutSecs;
// One message ptr for each message kinds
WebSocketMessagePtr _webSocketMessage;
WebSocketMessagePtr _webSocketErrorMessage;
WebSocketMessagePtr _webSocketOpenMessage;
WebSocketMessagePtr _webSocketCloseMessage;
// Subprotocols // Subprotocols
std::vector<std::string> _subProtocols; std::vector<std::string> _subProtocols;

View File

@ -6,6 +6,9 @@
#pragma once #pragma once
#include <cstdint>
#include <string>
namespace ix namespace ix
{ {
struct WebSocketCloseInfo struct WebSocketCloseInfo

View File

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <cstdint>
#include <string> #include <string>
namespace ix namespace ix
@ -17,5 +18,10 @@ namespace ix
int http_status = 0; int http_status = 0;
std::string reason; std::string reason;
bool decompressionError = false; bool decompressionError = false;
WebSocketErrorInfo()
{
;
}
}; };
} // namespace ix } // namespace ix

View File

@ -0,0 +1,12 @@
/*
* IXWebSocketMessage.cpp
* Author: Benjamin Sergeant
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
*/
#include "IXWebSocketMessage.h"
namespace ix
{
std::string WebSocketMessage::kStr("foo");
}

View File

@ -19,22 +19,23 @@ namespace ix
struct WebSocketMessage struct WebSocketMessage
{ {
WebSocketMessageType type; WebSocketMessageType type;
const std::string& str; std::string& str;
size_t wireSize; size_t wireSize;
WebSocketErrorInfo errorInfo; WebSocketErrorInfo errorInfo;
WebSocketOpenInfo openInfo; WebSocketOpenInfo openInfo;
WebSocketCloseInfo closeInfo; WebSocketCloseInfo closeInfo;
bool binary; bool binary;
static std::string kStr;
WebSocketMessage(WebSocketMessageType t, WebSocketMessage(WebSocketMessageType t,
const std::string& s, size_t w = 0,
size_t w, WebSocketErrorInfo e = WebSocketErrorInfo(),
WebSocketErrorInfo e, WebSocketOpenInfo o = WebSocketOpenInfo(),
WebSocketOpenInfo o, WebSocketCloseInfo c = WebSocketCloseInfo(),
WebSocketCloseInfo c,
bool b = false) bool b = false)
: type(t) : type(t)
, str(s) , str(WebSocketMessage::kStr)
, wireSize(w) , wireSize(w)
, errorInfo(e) , errorInfo(e)
, openInfo(o) , openInfo(o)
@ -43,6 +44,11 @@ namespace ix
{ {
; ;
} }
// void setStr(const std::string& s)
// {
// str = std::move(s);
// }
}; };
using WebSocketMessagePtr = std::unique_ptr<WebSocketMessage>; using WebSocketMessagePtr = std::unique_ptr<WebSocketMessage>;

View File

@ -6,6 +6,10 @@
#pragma once #pragma once
#include <cstdint>
#include <string>
#include "IXWebSocketHttpHeaders.h"
namespace ix namespace ix
{ {
struct WebSocketOpenInfo struct WebSocketOpenInfo

View File

@ -515,8 +515,10 @@ namespace ix
// //
if (ws.fin && _chunks.empty()) if (ws.fin && _chunks.empty())
{ {
emitMessage( emitMessage(_fragmentedMessageKind,
_fragmentedMessageKind, frameData, _receivedMessageCompressed, onMessageCallback); frameData,
_receivedMessageCompressed,
onMessageCallback);
_receivedMessageCompressed = false; _receivedMessageCompressed = false;
} }

View File

@ -6,4 +6,4 @@
#pragma once #pragma once
#define IX_WEBSOCKET_VERSION "9.2.5" #define IX_WEBSOCKET_VERSION "9.2.6"

View File

@ -6,8 +6,8 @@
#include "IXTest.h" #include "IXTest.h"
#include "catch.hpp" #include "catch.hpp"
#include <iostream>
#include "msgpack11.hpp" #include "msgpack11.hpp"
#include <iostream>
#include <ixwebsocket/IXSocket.h> #include <ixwebsocket/IXSocket.h>
#include <ixwebsocket/IXSocketFactory.h> #include <ixwebsocket/IXSocketFactory.h>
#include <ixwebsocket/IXWebSocket.h> #include <ixwebsocket/IXWebSocket.h>
@ -130,7 +130,8 @@ namespace
} }
else if (msg->type == ix::WebSocketMessageType::Error) else if (msg->type == ix::WebSocketMessageType::Error)
{ {
ss << "websocket_broadcast_client: " << _user << " Error ! " << msg->errorInfo.reason; ss << "websocket_broadcast_client: " << _user << " Error ! "
<< msg->errorInfo.reason;
log(ss.str()); log(ss.str());
} }
else if (msg->type == ix::WebSocketMessageType::Ping) else if (msg->type == ix::WebSocketMessageType::Ping)
@ -234,7 +235,7 @@ namespace
server.start(); server.start();
return true; return true;
} }
} // namespace ix } // namespace
TEST_CASE("Websocket_broadcast_server", "[websocket_server]") TEST_CASE("Websocket_broadcast_server", "[websocket_server]")
{ {
@ -247,7 +248,7 @@ TEST_CASE("Websocket_broadcast_server", "[websocket_server]")
std::string session = ix::generateSessionId(); std::string session = ix::generateSessionId();
std::vector<std::shared_ptr<WebSocketChat>> chatClients; std::vector<std::shared_ptr<WebSocketChat>> 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<WebSocketChat>(user, session, port));
@ -259,7 +260,7 @@ TEST_CASE("Websocket_broadcast_server", "[websocket_server]")
while (true) while (true)
{ {
bool allReady = true; bool allReady = true;
for (size_t i = 0 ; i < chatClients.size(); ++i) for (size_t i = 0; i < chatClients.size(); ++i)
{ {
allReady &= chatClients[i]->isReady(); allReady &= chatClients[i]->isReady();
} }
@ -269,7 +270,7 @@ TEST_CASE("Websocket_broadcast_server", "[websocket_server]")
for (int j = 0; j < 1000; j++) for (int j = 0; j < 1000; j++)
{ {
for (size_t i = 0 ; i < chatClients.size(); ++i) for (size_t i = 0; i < chatClients.size(); ++i)
{ {
chatClients[i]->sendMessage("hello world"); chatClients[i]->sendMessage("hello world");
} }
@ -291,7 +292,7 @@ TEST_CASE("Websocket_broadcast_server", "[websocket_server]")
// Stop all clients // Stop all clients
size_t messageCount = chatClients.size() * 50; size_t messageCount = chatClients.size() * 50;
for (size_t i = 0 ; i < chatClients.size(); ++i) for (size_t i = 0; i < chatClients.size(); ++i)
{ {
REQUIRE(chatClients[i]->getReceivedMessagesCount() >= messageCount); REQUIRE(chatClients[i]->getReceivedMessagesCount() >= messageCount);
chatClients[i]->stop(); chatClients[i]->stop();

View File

@ -268,8 +268,10 @@ int main(int argc, char** argv)
cobra2statsd->add_option("--port", statsdPort, "Statsd port"); cobra2statsd->add_option("--port", statsdPort, "Statsd port");
cobra2statsd->add_option("--prefix", prefix, "Statsd prefix"); cobra2statsd->add_option("--prefix", prefix, "Statsd prefix");
cobra2statsd->add_option("--fields", fields, "Extract fields for naming the event")->join(); cobra2statsd->add_option("--fields", fields, "Extract fields for naming the event")->join();
cobra2statsd->add_option("--gauge", gauge, "Value to extract, and use as a statsd gauge")->join(); cobra2statsd->add_option("--gauge", gauge, "Value to extract, and use as a statsd gauge")
cobra2statsd->add_option("--timer", timer, "Value to extract, and use as a statsd timer")->join(); ->join();
cobra2statsd->add_option("--timer", timer, "Value to extract, and use as a statsd timer")
->join();
cobra2statsd->add_option("channel", channel, "Channel")->required(); cobra2statsd->add_option("channel", channel, "Channel")->required();
cobra2statsd->add_flag("-v", verbose, "Verbose"); cobra2statsd->add_flag("-v", verbose, "Verbose");
cobra2statsd->add_option("--pidfile", pidfile, "Pid file"); cobra2statsd->add_option("--pidfile", pidfile, "Pid file");
@ -449,7 +451,8 @@ int main(int argc, char** argv)
} }
else if (app.got_subcommand("cobra_subscribe")) else if (app.got_subcommand("cobra_subscribe"))
{ {
ret = ix::ws_cobra_subscribe_main(cobraConfig, channel, filter, position, quiet, fluentd, runtime); ret = ix::ws_cobra_subscribe_main(
cobraConfig, channel, filter, position, quiet, fluentd, runtime);
} }
else if (app.got_subcommand("cobra_publish")) else if (app.got_subcommand("cobra_publish"))
{ {
@ -463,7 +466,7 @@ int main(int argc, char** argv)
{ {
if (!timer.empty() && !gauge.empty()) if (!timer.empty() && !gauge.empty())
{ {
spdlog::error("--gauge and --timer options are exclusive. " \ spdlog::error("--gauge and --timer options are exclusive. "
"you can only supply one"); "you can only supply one");
ret = 1; ret = 1;
} }

View File

@ -184,7 +184,7 @@ namespace ix
// Run for a duration, used by unittesting now // Run for a duration, used by unittesting now
else else
{ {
for (int i = 0 ; i < runtime; ++i) for (int i = 0; i < runtime; ++i)
{ {
auto duration = std::chrono::seconds(1); auto duration = std::chrono::seconds(1);
std::this_thread::sleep_for(duration); std::this_thread::sleep_for(duration);