Skip to content

Commit a04350b

Browse files
committed
Open streams_test_tmp file in temporary folder
The tests `streams_tests/streams_buffered_file` and `streams_tests/streams_buffered_file_rand` did not use a the temporary directory provided by `BasicTestingSetup`, so it was not possible to execute multiple of them in parallel. This fixes that. To reproduce, run ```sh parallel --halt now,fail=1 './src/test/test_bitcoin --run_test=streams_tests/streams_buffered_file_rand' -- ::: {1..1000} ``` This executes the test 1000 times, one job per CPU. It works on that commit but mergebase fails quickly.
1 parent 24abd83 commit a04350b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/test/streams_tests.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ BOOST_AUTO_TEST_CASE(streams_serializedata_xor)
215215

216216
BOOST_AUTO_TEST_CASE(streams_buffered_file)
217217
{
218-
FILE* file = fsbridge::fopen("streams_test_tmp", "w+b");
218+
fs::path streams_test_filename = m_args.GetDataDirBase() / "streams_test_tmp";
219+
FILE* file = fsbridge::fopen(streams_test_filename, "w+b");
220+
219221
// The value at each offset is the offset.
220222
for (uint8_t j = 0; j < 40; ++j) {
221223
fwrite(&j, 1, 1, file);
@@ -343,16 +345,17 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
343345
// We can explicitly close the file, or the destructor will do it.
344346
bf.fclose();
345347

346-
fs::remove("streams_test_tmp");
348+
fs::remove(streams_test_filename);
347349
}
348350

349351
BOOST_AUTO_TEST_CASE(streams_buffered_file_rand)
350352
{
351353
// Make this test deterministic.
352354
SeedInsecureRand(SeedRand::ZEROS);
353355

356+
fs::path streams_test_filename = m_args.GetDataDirBase() / "streams_test_tmp";
354357
for (int rep = 0; rep < 50; ++rep) {
355-
FILE* file = fsbridge::fopen("streams_test_tmp", "w+b");
358+
FILE* file = fsbridge::fopen(streams_test_filename, "w+b");
356359
size_t fileSize = InsecureRandRange(256);
357360
for (uint8_t i = 0; i < fileSize; ++i) {
358361
fwrite(&i, 1, 1, file);
@@ -453,7 +456,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_rand)
453456
maxPos = currentPos;
454457
}
455458
}
456-
fs::remove("streams_test_tmp");
459+
fs::remove(streams_test_filename);
457460
}
458461

459462
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)