Skip to content

Commit

Permalink
[OMON-384] Test backends writing to output by redirecting cout (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
awegrzyn authored Apr 13, 2021
1 parent 10c9602 commit b3b7246
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions test/testInfluxDb.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ BOOST_AUTO_TEST_CASE(simplySendMetric2)
{
using namespace std::string_literals;
auto monitoring = MonitoringFactory::Get("influxdb-stdout://");

std::stringstream coutRedirect;
std::streambuf* coutBuffer = std::cout.rdbuf(coutRedirect.rdbuf());

monitoring->send(Metric{"card"}
.addValue(40.217773, "temperature")
.addValue(0, "droppedPackets")
Expand All @@ -38,6 +42,9 @@ BOOST_AUTO_TEST_CASE(simplySendMetric2)
.addTag(tags::Key::ID, 3)
.addTag(tags::Key::Type, tags::Value::CRU)
);
std::string expected1 = "card,hostname=pcaldadam2.local,id=3,type=CRU temperature=40.2178,droppedPackets=0i,ctpClock=0.76817,localClock=240.471,totalPacketsPerSecond=0i 1618241730312076000\n";
BOOST_CHECK(expected1.compare(coutRedirect.str()));
coutRedirect.str(std::string());

monitoring->send(Metric{"link"}
.addValue("GBT/GBT"s, "gbtMode")
Expand All @@ -52,6 +59,10 @@ BOOST_AUTO_TEST_CASE(simplySendMetric2)
.addTag(tags::Key::CRU, 3)
.addTag(tags::Key::ID, 3)
);
std::string expected2 = R"(link,hostname=pcaldadam2.local,CRU=3,id=3 gbtMode="GBT/GBT",loopback="None",gbtMux="TTC:CTP",datapathMode="Continuous",datapath="Disabled",rxFreq=181.371,txFreq=196.25,status=0i,opticalPower=657.4 1618241730312104000)";
BOOST_CHECK(expected2.compare(coutRedirect.str()));

std::cout.rdbuf(coutBuffer);
}

BOOST_AUTO_TEST_CASE(InfluxDbv2)
Expand Down
2 changes: 1 addition & 1 deletion test/testMonitoringFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <chrono>
#include <vector>

#define BOOST_TEST_MODULE TestMonitoringFactory
#define BOOST_TEST_MODULE TestMonitoringVerbosityy
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <boost/lexical_cast.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/testThreads.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Test

using namespace o2::monitoring;

BOOST_AUTO_TEST_CASE(retrieveOtherParams)
BOOST_AUTO_TEST_CASE(runLibraryInMultipleThreads)
{
std::array<std::thread, 4> threads;
for (auto& thread : threads) {
Expand Down

0 comments on commit b3b7246

Please sign in to comment.