From 54f30eeebf530af8edf166328985d7248c9b0938 Mon Sep 17 00:00:00 2001 From: Rusty Conover Date: Fri, 16 Oct 2026 12:21:17 -0400 Subject: [PATCH] test: Give each C data integration test its own temp file NanoarrowIntegrationTestSchema and NanoarrowIntegrationTestBatch both wrote c_data_integration.tmp.json in the working directory. ctest runs each gtest case as its own process, so under ctest -j the two could overwrite or remove each other's file; the Batch test then failed reading the Schema test's JSON ("Expected num_batch between 0 and -1 but got 1"). Co-Authored-By: Claude Opus 5.5 (1M context) --- .../integration/c_data_integration_test.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/nanoarrow/integration/c_data_integration_test.cc b/src/nanoarrow/integration/c_data_integration_test.cc index 533dd703d..4dbace821 100644 --- a/src/nanoarrow/integration/c_data_integration_test.cc +++ b/src/nanoarrow/integration/c_data_integration_test.cc @@ -17,6 +17,7 @@ #include #include +#include #include @@ -25,19 +26,26 @@ #include "c_data_integration.h" // Not a true tempfile (writes to working directory), but is possibly more -// portable than mkstemp() +// portable than mkstemp(). The name includes the current test's name because ctest +// runs each test as a separate process, in parallel with the others: with a shared +// name, one test can overwrite or remove another test's file. class TempFile { public: - const char* name() { return name_; } + TempFile() + : name_(std::string("c_data_integration.") + + ::testing::UnitTest::GetInstance()->current_test_info()->name() + + ".tmp.json") {} + + const char* name() { return name_.c_str(); } ~TempFile() { - if (std::remove(name_) != 0) { + if (std::remove(name_.c_str()) != 0) { std::cerr << "Failed to remove '" << name_ << "'\n"; } } private: - const char* name_ = "c_data_integration.tmp.json"; + std::string name_; }; ArrowErrorCode WriteFileString(const std::string& content, const std::string& path) {