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

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


The following commit(s) were added to refs/heads/main by this push:
     new dc366060 chore: Give each C data integration test its own temp file 
(#969)
dc366060 is described below

commit dc366060a217b39956733aa4c4712970edb42f17
Author: Rusty Conover <[email protected]>
AuthorDate: Mon Oct 19 22:41:59 2026 -0400

    chore: Give each C data integration test its own temp file (#969)
    
    `NanoarrowIntegrationTestSchema` and `NanoarrowIntegrationTestBatch`
    (`c_data_integration_test.cc`) write their JSON to the same file,
    `c_data_integration.tmp.json`, in the working directory.
    `gtest_discover_tests()` registers each gtest case as a separate ctest
    test, so `ctest -j` runs the two as parallel processes. One can then
    overwrite or remove the other's file. When that happens the Batch test
    reads the Schema test's JSON and fails with:
    
    ```
    Expected num_batch between 0 and -1 but got 1
    ```
    
    In a full `ctest -j 12` run it fails now and then. I hit it on three
    unrelated branches in one day. With only these two tests running they
    start together, and on `main` `ctest -R NanoarrowIntegrationTest -j 2`
    failed 199 of 200 runs. Run serially, both pass.
    
    With this PR, `TempFile` includes the current test's name
    (`c_data_integration.<test name>.tmp.json`), so each test gets its own
    file. It's still written to the working directory, as before, which the
    existing comment keeps for portability. After the change the same loop
    failed 0 of 200 runs, and no temp files are left behind. Full ctest
    passes (macOS arm64, Debug, 388 tests, three runs).
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
---
 src/nanoarrow/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 533dd703..4dbace82 100644
--- a/src/nanoarrow/integration/c_data_integration_test.cc
+++ b/src/nanoarrow/integration/c_data_integration_test.cc
@@ -17,6 +17,7 @@
 
 #include <cstdio>
 #include <fstream>
+#include <string>
 
 #include <gtest/gtest.h>
 
@@ -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) {

Reply via email to