Skip to content

Commit

Permalink
[TEST] Fix sync problems in OTLP File exporter tests. (#3031)
Browse files Browse the repository at this point in the history
  • Loading branch information
owent authored Aug 16, 2024
1 parent 1203bcf commit b890969
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

1 comment on commit b890969

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: b890969 Previous: 1203bcf Ratio
BM_LockFreeBuffer/1 3248649.1203308105 ns/iter 1387792.8256988525 ns/iter 2.34

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.