This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 0be17e669e GH-37294: [C++] Use std::string for HasSubstr matcher 
(#37314)
0be17e669e is described below

commit 0be17e669e7d1b6c586b7d8ca17b67c64c87b04e
Author: David Li <[email protected]>
AuthorDate: Wed Aug 23 21:49:06 2023 -0400

    GH-37294: [C++] Use std::string for HasSubstr matcher (#37314)
    
    
    
    ### Rationale for this change
    
    Apparently not all versions of GTest/GMock handle `testing::HasSubstr` 
against a `std::string_view`.
    
    ### What changes are included in this PR?
    
    Explicitly wrap in `std::string`.
    
    ### Are these changes tested?
    
    They are the tests.
    
    ### Are there any user-facing changes?
    
    No.
    * Closes: #37294
    
    Authored-by: David Li <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 cpp/src/arrow/flight/flight_test.cc      | 47 +++++++++++++++++++-------------
 cpp/src/arrow/flight/test_definitions.cc |  2 +-
 2 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/cpp/src/arrow/flight/flight_test.cc 
b/cpp/src/arrow/flight/flight_test.cc
index c36c9eee71..020fb7b24e 100644
--- a/cpp/src/arrow/flight/flight_test.cc
+++ b/cpp/src/arrow/flight/flight_test.cc
@@ -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
 
@@ -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) {
@@ -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_;
diff --git a/cpp/src/arrow/flight/test_definitions.cc 
b/cpp/src/arrow/flight/test_definitions.cc
index c84c5a18ff..c43b693d84 100644
--- a/cpp/src/arrow/flight/test_definitions.cc
+++ b/cpp/src/arrow/flight/test_definitions.cc
@@ -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;

Reply via email to