fix tsan errors on macOS when running the unittest
This commit is contained in:
parent
169e225ccd
commit
d46ce7eb63
@ -12,6 +12,7 @@
|
||||
#include <iostream>
|
||||
#include <ixcrypto/IXHMac.h>
|
||||
#include <ixwebsocket/IXWebSocket.h>
|
||||
#include <ixcore/utils/IXCoreLogger.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace snake
|
||||
@ -47,7 +48,6 @@ namespace snake
|
||||
}}};
|
||||
|
||||
auto serializedResponse = response.dump();
|
||||
std::cout << "response = " << serializedResponse << std::endl;
|
||||
|
||||
ws->sendText(serializedResponse);
|
||||
}
|
||||
@ -58,7 +58,6 @@ namespace snake
|
||||
const nlohmann::json& pdu)
|
||||
{
|
||||
auto secret = getRoleSecret(appConfig, state->appkey(), state->role());
|
||||
std::cout << "secret = " << secret << std::endl;
|
||||
|
||||
if (secret.empty())
|
||||
{
|
||||
@ -74,12 +73,6 @@ namespace snake
|
||||
auto serverHash = ix::hmac(nonce, secret);
|
||||
std::string clientHash = pdu["body"]["credentials"]["hash"];
|
||||
|
||||
if (appConfig.verbose)
|
||||
{
|
||||
std::cout << serverHash << std::endl;
|
||||
std::cout << clientHash << std::endl;
|
||||
}
|
||||
|
||||
if (serverHash != clientHash)
|
||||
{
|
||||
nlohmann::json response = {
|
||||
@ -174,8 +167,6 @@ namespace snake
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "Connected to redis host " << hostname << ":" << port << std::endl;
|
||||
|
||||
// Now authenticate, if needed
|
||||
if (!appConfig.redisPassword.empty())
|
||||
{
|
||||
@ -187,7 +178,6 @@ namespace snake
|
||||
handleError("rtm/subscribe", ws, pdu, ss.str());
|
||||
return;
|
||||
}
|
||||
std::cout << "Auth response: " << authResponse << ":" << port << std::endl;
|
||||
}
|
||||
|
||||
int id = 0;
|
||||
@ -205,8 +195,6 @@ namespace snake
|
||||
};
|
||||
|
||||
auto responseCallback = [ws, pdu, &subscriptionId](const std::string& redisResponse) {
|
||||
std::cout << "Redis subscribe response: " << redisResponse << std::endl;
|
||||
|
||||
// Success
|
||||
nlohmann::json response = {{"action", "rtm/subscribe/ok"},
|
||||
{"id", pdu.value("id", 1)},
|
||||
@ -214,7 +202,12 @@ namespace snake
|
||||
ws->sendText(response.dump());
|
||||
};
|
||||
|
||||
std::cerr << "Subscribing to " << appChannel << "..." << std::endl;
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Subscribing to " << appChannel << "...";
|
||||
ix::IXCoreLogger::Log(ss.str().c_str());
|
||||
}
|
||||
|
||||
if (!redisClient.subscribe(appChannel, responseCallback, callback))
|
||||
{
|
||||
std::stringstream ss;
|
||||
@ -255,10 +248,7 @@ namespace snake
|
||||
const std::string& str)
|
||||
{
|
||||
auto pdu = nlohmann::json::parse(str);
|
||||
std::cout << "Got " << str << std::endl;
|
||||
|
||||
auto action = pdu["action"];
|
||||
std::cout << "action = " << action << std::endl;
|
||||
|
||||
if (action == "auth/handshake")
|
||||
{
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include "IXSnakeProtocol.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <ixcore/utils/IXCoreLogger.h>
|
||||
|
||||
|
||||
namespace snake
|
||||
{
|
||||
@ -43,8 +45,6 @@ namespace snake
|
||||
|
||||
bool SnakeServer::run()
|
||||
{
|
||||
std::cout << "Listening on " << _appConfig.hostname << ":" << _appConfig.port << std::endl;
|
||||
|
||||
auto factory = []() -> std::shared_ptr<ix::ConnectionState> {
|
||||
return std::make_shared<SnakeConnectionState>();
|
||||
};
|
||||
@ -57,15 +57,16 @@ namespace snake
|
||||
|
||||
webSocket->setOnMessageCallback(
|
||||
[this, webSocket, state](const ix::WebSocketMessagePtr& msg) {
|
||||
std::stringstream ss;
|
||||
if (msg->type == ix::WebSocketMessageType::Open)
|
||||
{
|
||||
std::cerr << "New connection" << std::endl;
|
||||
std::cerr << "id: " << state->getId() << std::endl;
|
||||
std::cerr << "Uri: " << msg->openInfo.uri << std::endl;
|
||||
std::cerr << "Headers:" << std::endl;
|
||||
ss << "New connection" << std::endl;
|
||||
ss << "id: " << state->getId() << std::endl;
|
||||
ss << "Uri: " << msg->openInfo.uri << std::endl;
|
||||
ss << "Headers:" << std::endl;
|
||||
for (auto it : msg->openInfo.headers)
|
||||
{
|
||||
std::cerr << it.first << ": " << it.second << std::endl;
|
||||
ss << it.first << ": " << it.second << std::endl;
|
||||
}
|
||||
|
||||
std::string appkey = parseAppKey(msg->openInfo.uri);
|
||||
@ -75,14 +76,14 @@ namespace snake
|
||||
if (!state->redisClient().connect(_appConfig.redisHosts[0],
|
||||
_appConfig.redisPort))
|
||||
{
|
||||
std::cerr << "Cannot connect to redis host" << std::endl;
|
||||
ss << "Cannot connect to redis host" << std::endl;
|
||||
}
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Close)
|
||||
{
|
||||
std::cerr << "Closed connection"
|
||||
<< " code " << msg->closeInfo.code << " reason "
|
||||
<< msg->closeInfo.reason << std::endl;
|
||||
ss << "Closed connection"
|
||||
<< " code " << msg->closeInfo.code << " reason "
|
||||
<< msg->closeInfo.reason << std::endl;
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Error)
|
||||
{
|
||||
@ -91,17 +92,18 @@ namespace snake
|
||||
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();
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Fragment)
|
||||
{
|
||||
std::cerr << "Received message fragment" << std::endl;
|
||||
ss << "Received message fragment" << std::endl;
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Message)
|
||||
{
|
||||
std::cerr << "Received " << msg->wireSize << " bytes" << std::endl;
|
||||
ss << "Received " << msg->wireSize << " bytes" << std::endl;
|
||||
processCobraMessage(state, webSocket, _appConfig, msg->str);
|
||||
}
|
||||
|
||||
ix::IXCoreLogger::Log(ss.str().c_str());
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -125,7 +125,8 @@ namespace
|
||||
{
|
||||
std::string filter;
|
||||
_conn.subscribe(channel, filter, [this](const Json::Value& msg) {
|
||||
std::cout << msg.toStyledString() << std::endl;
|
||||
spdlog::info("receive {}", msg.toStyledString());
|
||||
|
||||
if (!msg.isObject()) return;
|
||||
if (!msg.isMember("user")) return;
|
||||
if (!msg.isMember("text")) return;
|
||||
@ -335,15 +336,13 @@ TEST_CASE("Cobra_chat", "[cobra_chat]")
|
||||
REQUIRE(chatA.getReceivedMessagesCount() == 2);
|
||||
REQUIRE(chatB.getReceivedMessagesCount() == 3);
|
||||
|
||||
std::cout << "Incoming bytes: " << incomingBytes << std::endl;
|
||||
std::cout << "Outgoing bytes: " << outgoingBytes << std::endl;
|
||||
spdlog::info("Incoming bytes {}", incomingBytes);
|
||||
spdlog::info("Outgoing bytes {}", outgoingBytes);
|
||||
|
||||
std::cerr << "Stopping snake server... ";
|
||||
spdlog::info("Stopping snake server...");
|
||||
snakeServer.stop();
|
||||
std::cerr << "OK" << std::endl;
|
||||
|
||||
std::cerr << "Stopping redis server... ";
|
||||
spdlog::info("Stopping redis server...");
|
||||
redisServer.stop();
|
||||
std::cerr << "OK" << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -267,14 +267,12 @@ TEST_CASE("Cobra_Metrics_Publisher", "[cobra]")
|
||||
CHECK(gIds.count("sms_set_rate_control_id") == 1);
|
||||
CHECK(gIds.count("sms_set_blacklist_id") == 1);
|
||||
|
||||
std::cout << "Incoming bytes: " << incomingBytes << std::endl;
|
||||
std::cout << "Outgoing bytes: " << outgoingBytes << std::endl;
|
||||
spdlog::info("Incoming bytes {}", incomingBytes);
|
||||
spdlog::info("Outgoing bytes {}", outgoingBytes);
|
||||
|
||||
std::cerr << "Stopping snake server... ";
|
||||
spdlog::info("Stopping snake server...");
|
||||
snakeServer.stop();
|
||||
std::cerr << "OK" << std::endl;
|
||||
|
||||
std::cerr << "Stopping redis server... ";
|
||||
spdlog::info("Stopping redis server...");
|
||||
redisServer.stop();
|
||||
std::cerr << "OK" << std::endl;
|
||||
}
|
||||
|
5
third_party/jsoncpp/jsoncpp.cpp
vendored
5
third_party/jsoncpp/jsoncpp.cpp
vendored
@ -205,6 +205,7 @@ static inline void fixNumericLocale(char* begin, char* end) {
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <limits>
|
||||
#include <atomic>
|
||||
#if defined(__BORLANDC__)
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
@ -227,8 +228,8 @@ static inline void fixNumericLocale(char* begin, char* end) {
|
||||
#pragma warning(disable : 4996)
|
||||
#endif
|
||||
|
||||
static int const stackLimit_g = 1000;
|
||||
static int stackDepth_g = 0; // see readValue()
|
||||
static std::atomic<int> const stackLimit_g(1000);
|
||||
static std::atomic<int> stackDepth_g(0); // see readValue()
|
||||
|
||||
namespace Json {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user