You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "gahr (via GitHub)" <gi...@apache.org> on 2025/09/22 19:23:53 UTC

[PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

gahr opened a new pull request, #3496:
URL: https://github.com/apache/avro/pull/3496

   ## What is the purpose of the change
   
   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.
   
   This fixes AVRO-4185.
   
   ## Verifying this change
   
   This change is already covered by existing tests, such as StreamTests.
   
   ## Documentation
   
   - Does this pull request introduce a new feature? (no)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "thiru-mg (via GitHub)" <gi...@apache.org>.
thiru-mg commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2592030141


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   Remember the code is in test. The conflict happens when two people run the run the exactly at the same sub-microsecond. How likely is it? Even if happens, who cares? Just rerun the test. It is anyway better than what we have now.
   If we are still paranoid, let's `xor` the value of `random_device()` with `pid`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454277858


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/hs3e7355(v=vs.100)
   In the example code there is `// Note: tmpnam is deprecated; consider using tmpnam_s instead`
   
   Also in the build logs we can see:
   ```
   2025-10-23T08:00:00.3420284Z [ 68%] Linking CXX executable StreamTests
   2025-10-23T08:00:00.4955456Z /usr/bin/ld: CMakeFiles/StreamTests.dir/test/StreamTests.cc.o: in function `avro::stream::FileGuard::FileGuard()':
   2025-10-23T08:00:00.4957287Z /home/runner/work/avro/avro/lang/c++/test/StreamTests.cc:138:(.text._ZN4avro6stream9FileGuardC2Ev[_ZN4avro6stream9FileGuardC5Ev]+0x2a): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
   2025-10-23T08:00:00.6147334Z [ 68%] Built target StreamTests
   ```
   https://productionresultssa3.blob.core.windows.net/actions-results/abfc1b86-599c-48bd-a249-acda8f187020/workflow-job-run-670f0204-095a-5c23-a7d3-1d13fabc5e69/logs/job/job-logs.txt?rsct=text%2Fplain&se=2025-10-23T08%3A12%3A13Z&sig=9G%2FOy2gomdBnbYY%2FXTGGg%2Fza%2BjuKKXvqJVAL4xpemfg%3D&ske=2025-10-23T17%3A45%3A39Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2025-10-23T05%3A45%3A39Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2025-11-05&sp=r&spr=https&sr=b&st=2025-10-23T08%3A02%3A08Z&sv=2025-11-05



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454279037


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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); }

Review Comment:
   Not recover, but log it.
   But this is minor. We can ignore it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "gahr (via GitHub)" <gi...@apache.org>.
gahr commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454455638


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   > https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/hs3e7355(v=vs.100)
   > In the example code there is `// Note: tmpnam is deprecated; consider using tmpnam_s instead`
   
   Ah, I see that `tmpnam` is "obsolescent" in POSIX.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "gahr (via GitHub)" <gi...@apache.org>.
gahr commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454459084


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   If you're ok with bringing back a dependency on boost::filesystem, we can use https://www.boost.org/doc/libs/latest/libs/filesystem/doc/reference.html#unique_path



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2370322102


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   Using std::tmpnam(nullptr) is unsafe as it can cause race conditions and security vulnerabilities. Consider using std::filesystem::temp_directory_path() with a unique filename generator or platform-specific secure temporary file functions instead.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454082653


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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); }

Review Comment:
   Should we care about failures in `remove()` here ?
   Or since it is a test we don't care ?



##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   Isn't `tmpnam` deprecated ?
   
   Avro uses C++17, so we can use something like the following instead:
   ```
   #include <random>
   ...
   std::filesystem::path path = std::filesystem::temp_directory_path() / 
       ("avro_test_" + std::to_string(std::random_device{}()));
   ```



##########
lang/c++/test/StreamTests.cc:
##########
@@ -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(); };

Review Comment:
   ```suggestion
       const char* filename() const { return path.c_str(); }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "gahr (via GitHub)" <gi...@apache.org>.
gahr commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454219184


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   > Isn't `tmpnam` deprecated ?
   
   I can't find references to its deprecation.
   
   I don't think using `std::random_device` is a good idea, as it can be implemented using a PRNG, i.e., two tests running at the same time would produce the same number.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "thiru-mg (via GitHub)" <gi...@apache.org>.
thiru-mg commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2591534629


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   Since `random_device()` is meant to be used for seeding a PNRG and not directly for generating random numbers, we can do something like:
   
       static std::random_device rdev;
       static std::mt19937 rng(rdev());
   
       struct FileGuard {
           const std::filesystem::path path{ rng() };
           ...
        }



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "gahr (via GitHub)" <gi...@apache.org>.
gahr commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2592471205


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   Where is the spec that say that random_device must be implemented in such a way? In the standard I read it can generate the same sequence each time.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "thiru-mg (via GitHub)" <gi...@apache.org>.
thiru-mg commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2592030141


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   Remember the code is in test. The conflict happens when two people run the run the exactly at the same nanosecond. How likely is it? Even if happens, who cares? Just rerun the test. It is anyway better than what we have now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "gahr (via GitHub)" <gi...@apache.org>.
gahr commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454449814


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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); }

Review Comment:
   A bug, or some temporary condition. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "thiru-mg (via GitHub)" <gi...@apache.org>.
thiru-mg commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454295832


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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); }

Review Comment:
   If we fail to `remove()`, it is not catastrophic, but it would point to a bug somewhere. At lease we should report the error.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "gahr (via GitHub)" <gi...@apache.org>.
gahr commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454783534


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   I don't have a more standard way, sorry.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "gahr (via GitHub)" <gi...@apache.org>.
gahr commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2370356833


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   I don't think this concerns applies to this test code.



##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   I don't think this concerns apply to this test code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "gahr (via GitHub)" <gi...@apache.org>.
gahr commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2591620102


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   This doesn't address my concern: two processes can still generate the same sequence.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "gahr (via GitHub)" <gi...@apache.org>.
gahr commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2370356833


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   I don't think these concerns apply to this test code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "gahr (via GitHub)" <gi...@apache.org>.
gahr commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454202168


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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); }

Review Comment:
   I would not care, and I wouldn't know how to recover from such an error.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "thiru-mg (via GitHub)" <gi...@apache.org>.
thiru-mg commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454560197


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   We have been working on getting rid of boost dependencies altogether. I'd prefer not to bring it back.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "thiru-mg (via GitHub)" <gi...@apache.org>.
thiru-mg commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454307712


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   I don't think we should bother generating temp file by hand. According to https://en.cppreference.com/w/cpp/io/c/tmpnam.html, `std::tmpfile` is better. It has the added advantage that the file is automatically deleted upon closure.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AVRO-4185: [C++] Use a temp file in StreamTests [avro]

Posted by "gahr (via GitHub)" <gi...@apache.org>.
gahr commented on code in PR #3496:
URL: https://github.com/apache/avro/pull/3496#discussion_r2454447895


##########
lang/c++/test/StreamTests.cc:
##########
@@ -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) };

Review Comment:
   I'm all for `std::tmpfile`, but `fileOutputStream` wants a path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org