Skip to content

Commit

Permalink
apacheGH-37294: [C++] Use std::string for HasSubstr matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
lidavidm committed Aug 23, 2023
1 parent ebf03a6 commit 4d33aac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
47 changes: 28 additions & 19 deletions cpp/src/arrow/flight/flight_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,32 @@ const char kBasicPrefix[] = "Basic ";
const char kBearerPrefix[] = "Bearer ";
const char kAuthHeader[] = "authorization";

class OtelEnvironment : public ::testing::Environment {
public:
void SetUp() override {
#ifdef ARROW_WITH_OPENTELEMETRY
// The default tracer always generates no-op spans which have no
// span/trace ID. Set up a different tracer. Note, this needs to be run
// before Arrow uses OTel as GetTracer() gets a tracer once and keeps it
// in a static. Also, arrow::Future may GetTracer(). So this has to be
// done as a Googletest environment, which runs before any tests.
std::vector<std::unique_ptr<opentelemetry::sdk::trace::SpanProcessor>> processors;
auto provider =
opentelemetry::nostd::shared_ptr<opentelemetry::sdk::trace::TracerProvider>(
new opentelemetry::sdk::trace::TracerProvider(std::move(processors)));
opentelemetry::trace::Provider::SetTracerProvider(std::move(provider));

opentelemetry::context::propagation::GlobalTextMapPropagator::SetGlobalPropagator(
opentelemetry::nostd::shared_ptr<
opentelemetry::context::propagation::TextMapPropagator>(
new opentelemetry::trace::propagation::HttpTraceContext()));
#endif
}
};

static ::testing::Environment* kOtelEnvironment =
::testing::AddGlobalTestEnvironment(new OtelEnvironment);

//------------------------------------------------------------
// Common transport tests

Expand Down Expand Up @@ -1681,24 +1707,7 @@ class TracingTestServer : public FlightServerBase {

class TestTracing : public ::testing::Test {
public:
void SetUp() {
#ifdef ARROW_WITH_OPENTELEMETRY
// The default tracer always generates no-op spans which have no
// span/trace ID. Set up a different tracer. Note, this needs to
// be run before Arrow uses OTel as GetTracer() gets a tracer once
// and keeps it in a static.
std::vector<std::unique_ptr<opentelemetry::sdk::trace::SpanProcessor>> processors;
auto provider =
opentelemetry::nostd::shared_ptr<opentelemetry::sdk::trace::TracerProvider>(
new opentelemetry::sdk::trace::TracerProvider(std::move(processors)));
opentelemetry::trace::Provider::SetTracerProvider(std::move(provider));

opentelemetry::context::propagation::GlobalTextMapPropagator::SetGlobalPropagator(
opentelemetry::nostd::shared_ptr<
opentelemetry::context::propagation::TextMapPropagator>(
new opentelemetry::trace::propagation::HttpTraceContext()));
#endif

void SetUp() override {
ASSERT_OK(MakeServer<TracingTestServer>(
&server_, &client_,
[](FlightServerOptions* options) {
Expand All @@ -1711,7 +1720,7 @@ class TestTracing : public ::testing::Test {
return Status::OK();
}));
}
void TearDown() { ASSERT_OK(server_->Shutdown()); }
void TearDown() override { ASSERT_OK(server_->Shutdown()); }

protected:
std::unique_ptr<FlightClient> client_;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/flight/test_definitions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ void ErrorHandlingTest::TestAsyncGetFlightInfo() {

// The server-side arrow::Status-to-TransportStatus conversion puts the
// detail into the main error message.
EXPECT_THAT(detail->get().message(),
EXPECT_THAT(std::string(detail->get().message()),
::testing::HasSubstr("Expected message. Detail:"));

std::string_view arrow_code, arrow_message, binary_detail;
Expand Down

0 comments on commit 4d33aac

Please sign in to comment.