Merge branch 'bugfix/StopResponding_#58' into develop closes #58

develop
Geoffrey Merck 1 month ago
commit f2e5ae8508

@ -16,7 +16,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#pragma once #pragma once
#include <ctime> #include <ctime>
@ -39,13 +38,13 @@ private:
static uint m_prevMsgCount; static uint m_prevMsgCount;
static uint m_repeatThreshold; static uint m_repeatThreshold;
static void getTimeStamp(std::string& s); static void getTimeStamp(std::string &s);
template<typename... Args> template <typename... Args>
static void formatLogMessage(std::string& output, LOG_SEVERITY severity, const std::string & f, Args... args) static void formatLogMessage(std::string &output, LOG_SEVERITY severity, const std::string &f, Args... args)
{ {
assert(severity != LOG_NONE); assert(severity != LOG_NONE);
std::string severityStr(" "); std::string severityStr(" ");
switch (severity) switch (severity)
{ {
@ -58,7 +57,7 @@ private:
case LOG_FATAL: case LOG_FATAL:
severityStr.assign("FATAL "); severityStr.assign("FATAL ");
break; break;
case LOG_INFO : case LOG_INFO:
severityStr.assign("INFO "); severityStr.assign("INFO ");
break; break;
case LOG_WARNING: case LOG_WARNING:
@ -74,84 +73,113 @@ private:
std::string f2("[%s] "); std::string f2("[%s] ");
f2.append(f); f2.append(f);
CStringUtils::string_format_in_place(output, f2, severityStr.c_str(), args...); CStringUtils::string_format_in_place(output, f2, severityStr.c_str(), args...);
boost::trim_if(output, [](char c){ return c == '\n' || c == '\r' || c == ' ' || c == '\t'; }); boost::trim_if(output, [](char c)
{ return c == '\n' || c == '\r' || c == ' ' || c == '\t'; });
output.push_back('\n'); output.push_back('\n');
} }
public: public:
static void addTarget(CLogTarget * target); static void addTarget(CLogTarget *target);
static void finalise(); static void finalise();
static uint& getRepeatThreshold(); static uint &getRepeatThreshold();
template<typename... Args> static void logTrace(const std::string & f, Args... args) template <typename... Args>
static void logTrace(const std::string &f, Args... args)
{ {
log(LOG_TRACE, f, args...); log(LOG_TRACE, f, args...);
} }
template<typename... Args> static void logDebug(const std::string & f, Args... args) template <typename... Args>
static void logDebug(const std::string &f, Args... args)
{ {
log(LOG_DEBUG, f, args...); log(LOG_DEBUG, f, args...);
} }
template<typename... Args> static void logInfo(const std::string & f, Args... args) template <typename... Args>
static void logInfo(const std::string &f, Args... args)
{ {
log(LOG_INFO, f, args...); log(LOG_INFO, f, args...);
} }
template<typename... Args> static void logWarning(const std::string & f, Args... args) template <typename... Args>
static void logWarning(const std::string &f, Args... args)
{ {
log(LOG_WARNING, f, args...); log(LOG_WARNING, f, args...);
} }
template<typename... Args> static void logError(const std::string & f, Args... args) template <typename... Args>
static void logError(const std::string &f, Args... args)
{ {
log(LOG_ERROR, f, args...); log(LOG_ERROR, f, args...);
} }
template<typename... Args> static void logFatal(const std::string & f, Args... args) template <typename... Args>
static void logFatal(const std::string &f, Args... args)
{ {
log(LOG_FATAL, f, args...); log(LOG_FATAL, f, args...);
} }
template<typename... Args> static void log(LOG_SEVERITY severity, const std::string & f, Args... args) template <typename... Args>
static void log(LOG_SEVERITY severity, const std::string &f, Args... args)
{ {
// Protect against concurrent access to log targets
std::lock_guard lockTarget(m_targetsMutex); std::lock_guard lockTarget(m_targetsMutex);
if(m_targets.empty()) if (m_targets.empty())
return; return;
// Format the message with the given arguments
std::string msg; std::string msg;
formatLogMessage(msg, severity, f, args...); formatLogMessage(msg, severity, f, args...);
bool repeatedMsg = (msg.compare(m_prevMsg) == 0); bool repeatedMsg = (msg == m_prevMsg);
if(repeatedMsg && m_repeatThreshold > 0U) { // Handle repeated messages
if (repeatedMsg && m_repeatThreshold > 0U) {
m_prevMsgCount++; m_prevMsgCount++;
if(m_prevMsgCount >= m_repeatThreshold) if (m_prevMsgCount >= m_repeatThreshold)
{
// If threshold reached, skip logging this duplicate
return; return;
}
} }
m_prevMsg.assign(msg);
if(m_prevMsgCount >= m_repeatThreshold && !repeatedMsg && m_repeatThreshold > 0U) { // If we are leaving a repetition sequence, log a summary first
formatLogMessage(msg, severity, "Previous message repeated %d times", m_prevMsgCount - m_repeatThreshold + 1); if (!repeatedMsg && m_repeatThreshold > 0U && m_prevMsgCount >= m_repeatThreshold) {
m_prevMsg.clear(); std::string summary;
} formatLogMessage(summary, severity,
"Previous message repeated %d times",
std::string timestamp; m_prevMsgCount - m_repeatThreshold + 1);
getTimeStamp(timestamp);
std::string msgts; std::string ts;
CStringUtils::string_format_in_place(msgts, "[%s] %s", timestamp.c_str(), msg.c_str()); getTimeStamp(ts);
for(auto target : m_targets) { std::string summaryLine;
if(severity >= target->getLevel()) { CStringUtils::string_format_in_place(summaryLine, "[%s] %s", ts.c_str(), summary.c_str());
target->printLog(msgts);
for (auto target : m_targets)
{
if (severity >= target->getLevel())
target->printLog(summaryLine);
} }
}
if(m_prevMsgCount != 0 && !repeatedMsg) { // Reset repetition counter after summary
m_prevMsgCount = 0; m_prevMsgCount = 0;
log(severity, f, args ...);
} }
// Always log the current message
std::string ts;
getTimeStamp(ts);
std::string msgLine;
CStringUtils::string_format_in_place(msgLine, "[%s] %s", ts.c_str(), msg.c_str());
for (auto target : m_targets) {
if (severity >= target->getLevel())
target->printLog(msgLine);
}
// Save current message for repetition detection
m_prevMsg = msg;
} }
}; };

@ -19,6 +19,14 @@
#include <vector> #include <vector>
#include <climits> #include <climits>
#include <memory> #include <memory>
#include <thread>
#include <sstream>
#define THREAD_ID_STR(tid) ([](std::thread::id id){ \
std::stringstream ss; \
ss << id; \
return ss.str(); \
}(tid).c_str())
enum TRISTATE { enum TRISTATE {
STATE_FALSE, STATE_FALSE,

@ -118,6 +118,7 @@ int main(int argc, char *argv[])
TLog logConf; TLog logConf;
config->getLog(logConf); config->getLog(logConf);
CLog::finalise(); CLog::finalise();
CLog::getRepeatThreshold() = logConf.repeatThreshold;
if(logConf.displayLevel != LOG_NONE && !daemon.daemon) CLog::addTarget(new CLogConsoleTarget(logConf.displayLevel)); if(logConf.displayLevel != LOG_NONE && !daemon.daemon) CLog::addTarget(new CLogConsoleTarget(logConf.displayLevel));
if(logConf.fileLevel != LOG_NONE) CLog::addTarget(new CLogFileTarget(logConf.fileLevel, logConf.logDir, logConf.fileRoot, logConf.fileRotate)); if(logConf.fileLevel != LOG_NONE) CLog::addTarget(new CLogFileTarget(logConf.fileLevel, logConf.logDir, logConf.fileRoot, logConf.fileRotate));
@ -170,6 +171,7 @@ void CDStarGatewayApp::run()
bool CDStarGatewayApp::createThread() bool CDStarGatewayApp::createThread()
{ {
CLog::logTrace("Entering CDStarGatewayApp::createThread - Thread ID %s", THREAD_ID_STR(std::this_thread::get_id()));
// Log // Log
TLog log; TLog log;
m_config->getLog(log); m_config->getLog(log);
@ -257,6 +259,7 @@ bool CDStarGatewayApp::createThread()
bool atLeastOneRepeater = false; bool atLeastOneRepeater = false;
CRepeaterProtocolHandlerFactory repeaterProtocolFactory; CRepeaterProtocolHandlerFactory repeaterProtocolFactory;
for(unsigned int i = 0U; i < m_config->getRepeaterCount(); i++) { for(unsigned int i = 0U; i < m_config->getRepeaterCount(); i++) {
CLog::logTrace("Adding repeaters - CDStarGatewayApp::createThread - Rpt Idx %i - Thread ID %s", i, THREAD_ID_STR(std::this_thread::get_id()));
TRepeater rptrConfig; TRepeater rptrConfig;
m_config->getRepeater(i, rptrConfig); m_config->getRepeater(i, rptrConfig);
auto repeaterProtocolHandler = repeaterProtocolFactory.getRepeaterProtocolHandler(rptrConfig.hwType, gatewayConfig, rptrConfig.address, rptrConfig.port); auto repeaterProtocolHandler = repeaterProtocolFactory.getRepeaterProtocolHandler(rptrConfig.hwType, gatewayConfig, rptrConfig.address, rptrConfig.port);
@ -294,6 +297,8 @@ bool CDStarGatewayApp::createThread()
if(!ddEnabled) ddEnabled = rptrConfig.band.length() > 1U; if(!ddEnabled) ddEnabled = rptrConfig.band.length() > 1U;
} }
CLog::logTrace("Repeaters Added - CDStarGatewayApp::createThread - Thread ID %s", THREAD_ID_STR(std::this_thread::get_id()));
if(!atLeastOneRepeater) { if(!atLeastOneRepeater) {
CLog::logError("Error: no repeaters are enabled or opening network communication to repeater failed"); CLog::logError("Error: no repeaters are enabled or opening network communication to repeater failed");
return false; return false;
@ -306,40 +311,46 @@ bool CDStarGatewayApp::createThread()
auto ircddbVersionInfo = "linux_" + PRODUCT_NAME + "-" + VERSION; auto ircddbVersionInfo = "linux_" + PRODUCT_NAME + "-" + VERSION;
std::vector<CIRCDDB *> clients; std::vector<CIRCDDB *> clients;
for(unsigned int i=0; i < m_config->getIrcDDBCount(); i++) { for(unsigned int i=0; i < m_config->getIrcDDBCount(); i++) {
CLog::logTrace("Adding Ircddb - CDStarGatewayApp::createThread - Ircddb Idx %i - Thread ID %s", i, THREAD_ID_STR(std::this_thread::get_id()));
TircDDB ircDDBConfig; TircDDB ircDDBConfig;
m_config->getIrcDDB(i, ircDDBConfig); m_config->getIrcDDB(i, ircDDBConfig);
CLog::logInfo("ircDDB Network %d set to %s user: %s, Quadnet %d", i + 1,ircDDBConfig.hostname.c_str(), ircDDBConfig.username.c_str(), ircDDBConfig.isQuadNet); CLog::logInfo("ircDDB Network %d set to %s user: %s, Quadnet %d", i + 1,ircDDBConfig.hostname.c_str(), ircDDBConfig.username.c_str(), ircDDBConfig.isQuadNet);
CIRCDDB * ircDDB = new CIRCDDBClient(ircDDBConfig.hostname, 9007U, ircDDBConfig.username, ircDDBConfig.password, ircddbVersionInfo, gatewayConfig.address, ircDDBConfig.isQuadNet); CIRCDDB * ircDDB = new CIRCDDBClient(ircDDBConfig.hostname, 9007U, ircDDBConfig.username, ircDDBConfig.password, ircddbVersionInfo, gatewayConfig.address, ircDDBConfig.isQuadNet);
clients.push_back(ircDDB); clients.push_back(ircDDB);
} }
CLog::logTrace("Added Ircddb - CDStarGatewayApp::createThread - Ircddb Count %i - Thread ID %s", clients.size(), THREAD_ID_STR(std::this_thread::get_id()));
if(clients.size() > 0U) { if(clients.size() > 0U) {
CIRCDDBMultiClient* multiClient = new CIRCDDBMultiClient(clients); CIRCDDBMultiClient* multiClient = new CIRCDDBMultiClient(clients);
bool res = multiClient->open(); bool res = multiClient->open();
if (!res) { if (!res) {
CLog::logInfo("Cannot initialise the ircDDB protocol handler\n"); CLog::logError("Cannot initialise the ircDDB protocol handler\n");
return false; return false;
} }
m_thread->setIRC(multiClient); m_thread->setIRC(multiClient);
} }
CLog::logTrace("Setting Up Dextra CDStarGatewayApp::createThread - Thread ID %s", THREAD_ID_STR(std::this_thread::get_id()));
// Setup Dextra // Setup Dextra
TDextra dextraConfig; TDextra dextraConfig;
m_config->getDExtra(dextraConfig); m_config->getDExtra(dextraConfig);
CLog::logInfo("DExtra enabled: %d, max. dongles: %u, url: %s", int(dextraConfig.enabled), dextraConfig.maxDongles, dextraConfig.hostfileUrl.c_str()); CLog::logInfo("DExtra enabled: %d, max. dongles: %u, url: %s", int(dextraConfig.enabled), dextraConfig.maxDongles, dextraConfig.hostfileUrl.c_str());
m_thread->setDExtra(dextraConfig.enabled, dextraConfig.maxDongles); m_thread->setDExtra(dextraConfig.enabled, dextraConfig.maxDongles);
CLog::logTrace("Setting Up DCS CDStarGatewayApp::createThread - Thread ID %s", THREAD_ID_STR(std::this_thread::get_id()));
// Setup DCS // Setup DCS
TDCS dcsConfig; TDCS dcsConfig;
m_config->getDCS(dcsConfig); m_config->getDCS(dcsConfig);
CLog::logInfo("DCS enabled: %d, url: %s", int(dcsConfig.enabled), dcsConfig.hostfileUrl.c_str()); CLog::logInfo("DCS enabled: %d, url: %s", int(dcsConfig.enabled), dcsConfig.hostfileUrl.c_str());
m_thread->setDCS(dcsConfig.enabled); m_thread->setDCS(dcsConfig.enabled);
CLog::logTrace("Setting Up DPlus CDStarGatewayApp::createThread - Thread ID %s", THREAD_ID_STR(std::this_thread::get_id()));
// Setup DPlus // Setup DPlus
TDplus dplusConfig; TDplus dplusConfig;
m_config->getDPlus(dplusConfig); m_config->getDPlus(dplusConfig);
CLog::logInfo("D-Plus enabled: %d, max. dongles: %u, login: %s, url: %s", int(dplusConfig.enabled), dplusConfig.maxDongles, dplusConfig.login.c_str(), dplusConfig.hostfileUrl.c_str()); CLog::logInfo("D-Plus enabled: %d, max. dongles: %u, login: %s, url: %s", int(dplusConfig.enabled), dplusConfig.maxDongles, dplusConfig.login.c_str(), dplusConfig.hostfileUrl.c_str());
m_thread->setDPlus(dplusConfig.enabled, dplusConfig.maxDongles, dplusConfig.login); m_thread->setDPlus(dplusConfig.enabled, dplusConfig.maxDongles, dplusConfig.login);
CLog::logTrace("Setting Up XLX CDStarGatewayApp::createThread - Thread ID %s", THREAD_ID_STR(std::this_thread::get_id()));
// Setup XLX // Setup XLX
TXLX xlxConfig; TXLX xlxConfig;
m_config->getXLX(xlxConfig); m_config->getXLX(xlxConfig);

@ -58,19 +58,24 @@ IRCClient::IRCClient(IRCApplication *app, const std::string& update_channel, con
IRCClient::~IRCClient() IRCClient::~IRCClient()
{ {
delete m_proto; stopWork();
delete m_proto;
} }
void IRCClient::startWork() void IRCClient::startWork()
{ {
m_terminateThread = false; if (m_thread.joinable())
m_future = std::async(std::launch::async, &IRCClient::Entry, this); return;
m_terminateThread.store(false, std::memory_order_relaxed);
m_thread = std::thread(&IRCClient::Entry, this);
} }
void IRCClient::stopWork() void IRCClient::stopWork()
{ {
m_terminateThread = true; m_terminateThread.store(true, std::memory_order_relaxed);
m_future.get(); if (m_thread.joinable())
m_thread.join();
} }
void IRCClient::Entry() void IRCClient::Entry()
@ -98,7 +103,7 @@ void IRCClient::Entry()
switch (state) { switch (state) {
case 0: case 0:
if (m_terminateThread) { if (m_terminateThread.load(std::memory_order_relaxed)) {
CLog::logInfo("IRCClient::Entry: thread terminated at state=%d\n", state); CLog::logInfo("IRCClient::Entry: thread terminated at state=%d\n", state);
return; return;
} }
@ -118,7 +123,7 @@ void IRCClient::Entry()
break; break;
case 1: case 1:
if (m_terminateThread) { if (m_terminateThread.load(std::memory_order_relaxed)) {
CLog::logInfo("IRCClient::Entry: thread terminated at state=%d\n", state); CLog::logInfo("IRCClient::Entry: thread terminated at state=%d\n", state);
return; return;
} }
@ -261,7 +266,7 @@ void IRCClient::Entry()
case 5: case 5:
if (m_terminateThread) if (m_terminateThread.load(std::memory_order_relaxed))
state = 6; state = 6;
else { else {
if (m_recvQ->isEOF()) { if (m_recvQ->isEOF()) {

@ -22,7 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once #pragma once
#include <string> #include <string>
#include <future> #include <thread>
#include <atomic>
#include "IRCReceiver.h" #include "IRCReceiver.h"
#include "IRCMessageQueue.h" #include "IRCMessageQueue.h"
@ -47,13 +48,13 @@ private:
unsigned int m_port; unsigned int m_port;
std::string m_callsign; std::string m_callsign;
std::string m_password; std::string m_password;
bool m_terminateThread; std::atomic<bool> m_terminateThread{false};
IRCReceiver *m_recv; IRCReceiver *m_recv;
IRCMessageQueue *m_recvQ; IRCMessageQueue *m_recvQ;
IRCMessageQueue *m_sendQ; IRCMessageQueue *m_sendQ;
IRCProtocol *m_proto; IRCProtocol *m_proto;
IRCApplication *m_app; IRCApplication *m_app;
std::future<void> m_future; std::thread m_thread;
};
};

@ -112,7 +112,7 @@ public:
std::regex m_fromPattern; std::regex m_fromPattern;
bool m_initReady; bool m_initReady;
bool m_terminateThread; std::atomic<bool> m_terminateThread{false};
std::map<std::string, IRCDDBAppUserObject> m_userMap; std::map<std::string, IRCDDBAppUserObject> m_userMap;
std::mutex m_userMapMutex; std::mutex m_userMapMutex;
@ -151,8 +151,10 @@ IRCDDBApp::IRCDDBApp(const std::string& u_chan)
IRCDDBApp::~IRCDDBApp() IRCDDBApp::~IRCDDBApp()
{ {
delete m_d->m_sendQ; stopWork();
delete m_d;
delete m_d->m_sendQ;
delete m_d;
} }
void IRCDDBApp::rptrQTH(const std::string& callsign, double latitude, double longitude, const std::string& desc1, const std::string& desc2, const std::string& infoURL) void IRCDDBApp::rptrQTH(const std::string& callsign, double latitude, double longitude, const std::string& desc1, const std::string& desc2, const std::string& infoURL)
@ -279,14 +281,18 @@ IRCMessage *IRCDDBApp::getReplyMessage()
void IRCDDBApp::startWork() void IRCDDBApp::startWork()
{ {
m_d->m_terminateThread = false; if (m_thread.joinable())
m_future = std::async(std::launch::async, &IRCDDBApp::Entry, this); return;
m_d->m_terminateThread.store(false, std::memory_order_relaxed);
m_thread = std::thread(&IRCDDBApp::Entry, this);
} }
void IRCDDBApp::stopWork() void IRCDDBApp::stopWork()
{ {
m_d->m_terminateThread = true; m_d->m_terminateThread.store(true, std::memory_order_relaxed);
m_future.get(); if (m_thread.joinable())
m_thread.join();
} }
unsigned int IRCDDBApp::calculateUsn(const std::string& nick) unsigned int IRCDDBApp::calculateUsn(const std::string& nick)
@ -996,7 +1002,7 @@ static bool needsDatabaseUpdate(int tableID)
void IRCDDBApp::Entry() void IRCDDBApp::Entry()
{ {
int sendlistTableID = 0; int sendlistTableID = 0;
while (!m_d->m_terminateThread) { while (!m_d->m_terminateThread.load(std::memory_order_relaxed)) {
if (m_d->m_timer > 0) if (m_d->m_timer > 0)
m_d->m_timer--; m_d->m_timer--;
switch(m_d->m_state) { switch(m_d->m_state) {

@ -25,7 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "IRCApplication.h" #include "IRCApplication.h"
#include <string> #include <string>
#include <future> #include <thread>
#include <atomic>
#include <ctime> #include <ctime>
#include <vector> #include <vector>
@ -99,6 +100,7 @@ private:
IRCDDBAppPrivate *m_d; IRCDDBAppPrivate *m_d;
time_t m_maxTime; time_t m_maxTime;
std::future<void> m_future; std::thread m_thread;
}; };

@ -51,7 +51,7 @@ CIRCDDBClient::~CIRCDDBClient()
// A false return implies a network error, or unable to log in // A false return implies a network error, or unable to log in
bool CIRCDDBClient::open() bool CIRCDDBClient::open()
{ {
CLog::logInfo("start client and app\n"); CLog::logInfo("IRCDDB start client and app\n");
m_d->client->startWork(); m_d->client->startWork();
m_d->m_app->startWork(); m_d->m_app->startWork();
return true; return true;

@ -158,6 +158,7 @@ The testing framwework used is Google Test.
# 6. Version History # 6. Version History
## 6.1. Version 1.0 ## 6.1. Version 1.0
- [**Improvement**] Improve threading handling ([#58](https://github.com/F4FXL/DStarGateway/issues/58))
- [**Improvement**] Add Add an option to disable logging of ircddb traffic ([#59](https://github.com/F4FXL/DStarGateway/issues/59)) - [**Improvement**] Add Add an option to disable logging of ircddb traffic ([#59](https://github.com/F4FXL/DStarGateway/issues/59))
- [**Bugfix**] Fix repeater not reverting to startup reflector after issueing a command through remote control. ([#57](https://github.com/F4FXL/DStarGateway/issues/57)) - [**Bugfix**] Fix repeater not reverting to startup reflector after issueing a command through remote control. ([#57](https://github.com/F4FXL/DStarGateway/issues/57))
- [**Bugfix**] Fix corrupted slow data leading to DV Text Message not being sent to ircddb. Thanks to Manfred DL1JM for all the testing. ([#55](https://github.com/F4FXL/DStarGateway/issues/55)) - [**Bugfix**] Fix corrupted slow data leading to DV Text Message not being sent to ircddb. Thanks to Manfred DL1JM for all the testing. ([#55](https://github.com/F4FXL/DStarGateway/issues/55))

@ -52,6 +52,18 @@ namespace LogRepeatTests
EXPECT_THAT(m_logTarget->m_messages[1].c_str(), EndsWith("[ERROR ] Two Message\n")); EXPECT_THAT(m_logTarget->m_messages[1].c_str(), EndsWith("[ERROR ] Two Message\n"));
} }
TEST_F(LogRepeat, ThreeIdenticalMessageThreshold0) {
CLog::getRepeatThreshold() = 0U;
CLog::logError("One Message");
CLog::logError("One Message");
CLog::logError("One Message");
EXPECT_EQ(3, m_logTarget->m_messages.size()) << "There should be 3 messages in the log.";
EXPECT_THAT(m_logTarget->m_messages[0].c_str(), EndsWith("[ERROR ] One Message\n"));
EXPECT_THAT(m_logTarget->m_messages[1].c_str(), EndsWith("[ERROR ] One Message\n"));
EXPECT_THAT(m_logTarget->m_messages[2].c_str(), EndsWith("[ERROR ] One Message\n"));
}
TEST_F(LogRepeat, ThreeIdenticalMessageThreshold1) { TEST_F(LogRepeat, ThreeIdenticalMessageThreshold1) {
CLog::getRepeatThreshold() = 1U; CLog::getRepeatThreshold() = 1U;
CLog::logError("One Message"); CLog::logError("One Message");
@ -62,6 +74,34 @@ namespace LogRepeatTests
EXPECT_THAT(m_logTarget->m_messages[0].c_str(), EndsWith("[ERROR ] One Message\n")); EXPECT_THAT(m_logTarget->m_messages[0].c_str(), EndsWith("[ERROR ] One Message\n"));
} }
TEST_F(LogRepeat, NineIdenticalMessageTwoDifferentThreshold0) {
CLog::getRepeatThreshold() = 0U;
CLog::logError("One Message");
CLog::logError("One Message");
CLog::logError("One Message");
CLog::logError("One Message");
CLog::logError("One Message");
CLog::logError("One Message");
CLog::logError("One Message");
CLog::logError("One Message");
CLog::logError("One Message");
CLog::logError("Another Message");
CLog::logError("And here is another Message");
EXPECT_EQ(11, m_logTarget->m_messages.size()) << "There should be two message in the log.";
EXPECT_THAT(m_logTarget->m_messages[0].c_str(), EndsWith("[ERROR ] One Message\n"));
EXPECT_THAT(m_logTarget->m_messages[1].c_str(), EndsWith("[ERROR ] One Message\n"));
EXPECT_THAT(m_logTarget->m_messages[2].c_str(), EndsWith("[ERROR ] One Message\n"));
EXPECT_THAT(m_logTarget->m_messages[3].c_str(), EndsWith("[ERROR ] One Message\n"));
EXPECT_THAT(m_logTarget->m_messages[4].c_str(), EndsWith("[ERROR ] One Message\n"));
EXPECT_THAT(m_logTarget->m_messages[5].c_str(), EndsWith("[ERROR ] One Message\n"));
EXPECT_THAT(m_logTarget->m_messages[6].c_str(), EndsWith("[ERROR ] One Message\n"));
EXPECT_THAT(m_logTarget->m_messages[7].c_str(), EndsWith("[ERROR ] One Message\n"));
EXPECT_THAT(m_logTarget->m_messages[8].c_str(), EndsWith("[ERROR ] One Message\n"));
EXPECT_THAT(m_logTarget->m_messages[9].c_str(), EndsWith("[ERROR ] Another Message\n"));
EXPECT_THAT(m_logTarget->m_messages[10].c_str(), EndsWith("[ERROR ] And here is another Message\n"));
}
TEST_F(LogRepeat, NineIdenticalMessageTwoDifferentThreshold1) { TEST_F(LogRepeat, NineIdenticalMessageTwoDifferentThreshold1) {
CLog::getRepeatThreshold() = 1U; CLog::getRepeatThreshold() = 1U;
CLog::logError("One Message"); CLog::logError("One Message");

Loading…
Cancel
Save

Powered by TurnKey Linux.