From d0259cd3ba14b0ba3bb5107abf12480323e9e8c1 Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Mon, 22 Sep 2025 19:14:05 +0000 Subject: [PATCH 1/2] AVRO-4185: [C++] Use a temp file in StreamTests StreamTests uses the test_str.bin file. This is problematic in our setup because we build and test 32-bit and 64-bit versions in parallel. When the 32-bit and 64-bit StreamTest happen to run concurrently, one ends up deleting the file that the other is trying to read. My solution here is to use a temporary file instead of the hard-coded test_str.bin. --- lang/c++/test/StreamTests.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lang/c++/test/StreamTests.cc b/lang/c++/test/StreamTests.cc index d14558ecd28..f179e8dbed9 100644 --- a/lang/c++/test/StreamTests.cc +++ b/lang/c++/test/StreamTests.cc @@ -21,6 +21,7 @@ #include #include +#include #include namespace avro { @@ -134,36 +135,34 @@ void testNonEmpty2(const TestData &td) { Verify1()(*is, td.dataSize); } -static const char filename[] = "test_str.bin"; - -struct FileRemover { - const std::filesystem::path file; - explicit FileRemover(const char *fn) : file(fn) {} - ~FileRemover() { std::filesystem::remove(file); } +struct FileGuard { + const std::filesystem::path path{ std::tmpnam(nullptr) }; + ~FileGuard() { std::filesystem::remove(path); } + const char* filename() const { return path.c_str(); }; }; template void testEmpty_fileStream() { - FileRemover fr(filename); + FileGuard fg; { - std::unique_ptr os = fileOutputStream(filename); + std::unique_ptr os = fileOutputStream(fg.filename()); } - std::unique_ptr is = fileInputStream(filename); + std::unique_ptr is = fileInputStream(fg.filename()); V() (*is); } template void testNonEmpty_fileStream(const TestData &td) { - FileRemover fr(filename); + FileGuard fg; { - std::unique_ptr os = fileOutputStream(filename, + std::unique_ptr os = fileOutputStream(fg.filename(), td.chunkSize); F() (*os, td.dataSize); } - std::unique_ptr is = fileInputStream(filename, td.chunkSize); + std::unique_ptr is = fileInputStream(fg.filename(), td.chunkSize); V() (*is, td.dataSize); } From af1c75bc6a308548c62abbfa5a4d9ae7d331e1b4 Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Thu, 23 Oct 2025 09:34:46 +0200 Subject: [PATCH 2/2] Update lang/c++/test/StreamTests.cc Co-authored-by: Martin Grigorov --- lang/c++/test/StreamTests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/c++/test/StreamTests.cc b/lang/c++/test/StreamTests.cc index f179e8dbed9..71f889469a1 100644 --- a/lang/c++/test/StreamTests.cc +++ b/lang/c++/test/StreamTests.cc @@ -138,7 +138,7 @@ void testNonEmpty2(const TestData &td) { struct FileGuard { const std::filesystem::path path{ std::tmpnam(nullptr) }; ~FileGuard() { std::filesystem::remove(path); } - const char* filename() const { return path.c_str(); }; + const char* filename() const { return path.c_str(); } }; template