From 7d56f8841600d04f4e712c6a41d32186f981fd6c Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Fri, 3 Dec 2021 19:19:13 +0000 Subject: [PATCH 1/2] ARROW-14980: [C++] GCS tests use PYTHON environment variable --- cpp/src/arrow/filesystem/gcsfs_test.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cpp/src/arrow/filesystem/gcsfs_test.cc b/cpp/src/arrow/filesystem/gcsfs_test.cc index 3024d329f70f..f22bee5b41fd 100644 --- a/cpp/src/arrow/filesystem/gcsfs_test.cc +++ b/cpp/src/arrow/filesystem/gcsfs_test.cc @@ -78,11 +78,24 @@ class GcsIntegrationTest : public ::testing::Test { // Initialize a PRNG with a small amount of entropy. generator_ = std::mt19937_64(std::random_device()()); port_ = std::to_string(GetListenPort()); - auto exe_path = bp::search_path("python3"); - ASSERT_THAT(exe_path, Not(IsEmpty())); - - server_process_ = bp::child(boost::this_process::environment(), exe_path, "-m", - "testbench", "--port", port_, group_); + std::vector names{"python3", "python"}; + // If the build script or application developer provides a value in the PYTHON + // environment variable, then just use that. + if (const auto* env = std::getenv("PYTHON")) { + names = {env}; + } + for (const auto& interpreter : names) { + auto exe_path = bp::search_path(interpreter); + if (exe_path.empty()) continue; + + server_process_ = bp::child(boost::this_process::environment(), exe_path, "-m", + "testbench", "--port", port_, group_); + if (server_process_.valid() && server_process_.running()) break; + server_process_.terminate(); + server_process_.wait(); + } + ASSERT_TRUE(server_process_.valid()); + ASSERT_TRUE(server_process_.running()); // Create a bucket and a small file in the testbench. This makes it easier to // bootstrap GcsFileSystem and its tests. From e3334ba5d56addc2092b8dcefeee089f586ff8de Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Wed, 8 Dec 2021 14:57:12 +0000 Subject: [PATCH 2/2] Improve error messages --- cpp/src/arrow/filesystem/gcsfs_test.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cpp/src/arrow/filesystem/gcsfs_test.cc b/cpp/src/arrow/filesystem/gcsfs_test.cc index f22bee5b41fd..4f88aaced615 100644 --- a/cpp/src/arrow/filesystem/gcsfs_test.cc +++ b/cpp/src/arrow/filesystem/gcsfs_test.cc @@ -84,18 +84,26 @@ class GcsIntegrationTest : public ::testing::Test { if (const auto* env = std::getenv("PYTHON")) { names = {env}; } + auto error = std::string( + "Cloud not start GCS emulator." + " Used the following list of python interpreter names:"); for (const auto& interpreter : names) { auto exe_path = bp::search_path(interpreter); - if (exe_path.empty()) continue; + error += " " + interpreter; + if (exe_path.empty()) { + error += " (exe not found)"; + continue; + } server_process_ = bp::child(boost::this_process::environment(), exe_path, "-m", "testbench", "--port", port_, group_); if (server_process_.valid() && server_process_.running()) break; + error += " (failed to start)"; server_process_.terminate(); server_process_.wait(); } - ASSERT_TRUE(server_process_.valid()); - ASSERT_TRUE(server_process_.running()); + ASSERT_TRUE(server_process_.valid()) << error; + ASSERT_TRUE(server_process_.running()) << error; // Create a bucket and a small file in the testbench. This makes it easier to // bootstrap GcsFileSystem and its tests.