Skip to content

Commit

Permalink
Merge pull request #61 from open-telemetry/main
Browse files Browse the repository at this point in the history
[TEST] Fix sync problems in OTLP File exporter tests. (open-telemetry#3031)
  • Loading branch information
malkia authored Aug 16, 2024
2 parents 9ba0979 + b890969 commit 6d9e5b0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
24 changes: 18 additions & 6 deletions exporters/otlp/test/otlp_file_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "nlohmann/json.hpp"

#include <chrono>
#include <iostream>
#include <sstream>

using namespace testing;
Expand Down Expand Up @@ -112,13 +113,24 @@ class OtlpFileExporterTestPeer : public ::testing::Test

provider->ForceFlush();

output.flush();
output.sync();
auto check_json_text = output.str();
if (!check_json_text.empty())
{
auto check_json = nlohmann::json::parse(output.str(), nullptr, false);
auto resource_span = *check_json["resourceSpans"].begin();
auto scope_span = *resource_span["scopeSpans"].begin();
auto span = *scope_span["spans"].begin();
auto received_trace_id = span["traceId"].get<std::string>();
EXPECT_EQ(received_trace_id, report_trace_id);
auto check_json = nlohmann::json::parse(check_json_text, nullptr, false);
if (!check_json.is_discarded())
{
auto resource_span = *check_json["resourceSpans"].begin();
auto scope_span = *resource_span["scopeSpans"].begin();
auto span = *scope_span["spans"].begin();
auto received_trace_id = span["traceId"].get<std::string>();
EXPECT_EQ(received_trace_id, report_trace_id);
}
else
{
FAIL() << "Failed to parse json:" << check_json_text;
}
}
}
};
Expand Down
6 changes: 5 additions & 1 deletion exporters/otlp/test/otlp_file_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ class OtlpFileLogRecordExporterTestPeer : public ::testing::Test

provider->ForceFlush();

output.flush();
output.sync();
auto check_json_text = output.str();
if (!check_json_text.empty())
{
auto check_json = nlohmann::json::parse(output.str(), nullptr, false);
auto check_json = nlohmann::json::parse(check_json_text, nullptr, false);
auto resource_logs = *check_json["resourceLogs"].begin();
auto scope_logs = *resource_logs["scopeLogs"].begin();
auto scope = scope_logs["scope"];
Expand Down
18 changes: 15 additions & 3 deletions exporters/otlp/test/otlp_file_metric_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ class OtlpFileMetricExporterTestPeer : public ::testing::Test

exporter->ForceFlush();

output.flush();
output.sync();
auto check_json_text = output.str();
if (!check_json_text.empty())
{
auto check_json = nlohmann::json::parse(output.str(), nullptr, false);
auto check_json = nlohmann::json::parse(check_json_text, nullptr, false);

auto resource_metrics = *check_json["resourceMetrics"].begin();
auto scope_metrics = *resource_metrics["scopeMetrics"].begin();
Expand Down Expand Up @@ -167,8 +171,12 @@ class OtlpFileMetricExporterTestPeer : public ::testing::Test

exporter->ForceFlush();

output.flush();
output.sync();
auto check_json_text = output.str();
if (!check_json_text.empty())
{
auto check_json = nlohmann::json::parse(output.str(), nullptr, false);
auto check_json = nlohmann::json::parse(check_json_text, nullptr, false);

auto resource_metrics = *check_json["resourceMetrics"].begin();
auto scope_metrics = *resource_metrics["scopeMetrics"].begin();
Expand Down Expand Up @@ -233,8 +241,12 @@ class OtlpFileMetricExporterTestPeer : public ::testing::Test

exporter->ForceFlush();

output.flush();
output.sync();
auto check_json_text = output.str();
if (!check_json_text.empty())
{
auto check_json = nlohmann::json::parse(output.str(), nullptr, false);
auto check_json = nlohmann::json::parse(check_json_text, nullptr, false);

auto resource_metrics = *check_json["resourceMetrics"].begin();
auto scope_metrics = *resource_metrics["scopeMetrics"].begin();
Expand Down

0 comments on commit 6d9e5b0

Please sign in to comment.