diff --git a/src/chunks/writer.odin b/src/chunks/writer.odin index b4858b3..57101fc 100644 --- a/src/chunks/writer.odin +++ b/src/chunks/writer.odin @@ -68,7 +68,7 @@ compute_chunk_path :: proc( err: Error, ) { - @(static) buf: [20]u8 + buf: [20]u8 // not @(static), that would make it shared across all threads! chunk_index_str := strconv.write_int(buf[:], cast(i64)chunk_index, 10) chunk_name := strings.concatenate({CHUNK, chunk_index_str}, allocator) diff --git a/tests/helpers.odin b/tests/helpers.odin index 44724f7..b71501f 100644 --- a/tests/helpers.odin +++ b/tests/helpers.odin @@ -21,15 +21,19 @@ Test_State :: struct { test_state_init :: proc( t: ^testing.T, + name: string, allocator := context.allocator, ) -> Test_State { ensure_dir(t, TEST_INPUT_DIR) ensure_dir(t, TEST_OUTPUT_DIR) - temp_input_path, err := os.mkdir_temp(TEST_INPUT_DIR, "", allocator) + // Use the test name as the pattern so parallel tests with the same + // RNG seed generate distinct temp directory names. + + temp_input_path, err := os.mkdir_temp(TEST_INPUT_DIR, name, allocator) testing.expect(t, err == nil, os.error_string(err)) - temp_output_path, err2 := os.mkdir_temp(TEST_OUTPUT_DIR, "", allocator) + temp_output_path, err2 := os.mkdir_temp(TEST_OUTPUT_DIR, name, allocator) testing.expect(t, err2 == nil, os.error_string(err2)) return Test_State { @@ -59,10 +63,8 @@ test_state_destroy :: proc( // ----------------------------------------- ensure_dir :: proc(t: ^testing.T, dir: string) { - if !os.exists(dir) { - err := os.make_directory_all(dir) - testing.expect(t, err == nil, os.error_string(err)) - } + err := os.make_directory_all(dir) + testing.expect(t, err == nil || err == .Exist, os.error_string(err)) // TOCTOU safe } create_file :: proc( @@ -77,10 +79,8 @@ create_file :: proc( defer delete(relpath, allocator) dir := os.dir(relpath) - if !os.exists(dir) { - err2 := os.make_directory_all(dir) - testing.expect(t, err2 == nil, os.error_string(err2)) - } + err2 := os.make_directory_all(dir) + testing.expect(t, err2 == nil || err2 == .Exist, os.error_string(err2)) // TOCTOU safe file, err3 := os.create(relpath) testing.expect(t, err3 == nil, os.error_string(err3)) diff --git a/tests/tests.odin b/tests/tests.odin index 64e5de3..85e09bc 100644 --- a/tests/tests.odin +++ b/tests/tests.odin @@ -6,7 +6,7 @@ import "core:testing" single_tiny_file_read_from_chunk :: proc(t: ^testing.T) { // Arrange - ts := test_state_init(t) + ts := test_state_init(t, #procedure) defer test_state_destroy(&ts, t) delete_path(&ts, t, "") @@ -27,7 +27,7 @@ single_tiny_file_read_from_chunk :: proc(t: ^testing.T) { single_file_single_chunk_read_from_path :: proc(t: ^testing.T) { // Arrange - ts := test_state_init(t) + ts := test_state_init(t, #procedure) defer test_state_destroy(&ts, t) delete_path(&ts, t, "") @@ -49,7 +49,7 @@ single_file_single_chunk_read_from_path :: proc(t: ^testing.T) { multiple_files_single_chunk_read_from_chunk :: proc(t: ^testing.T) { // Arrange - ts := test_state_init(t) + ts := test_state_init(t, #procedure) defer test_state_destroy(&ts, t) delete_path(&ts, t, "") @@ -76,7 +76,7 @@ multiple_files_single_chunk_read_from_chunk :: proc(t: ^testing.T) { multiple_files_single_chunk_read_from_path :: proc(t: ^testing.T) { // Arrange - ts := test_state_init(t) + ts := test_state_init(t, #procedure) defer test_state_destroy(&ts, t) delete_path(&ts, t, "")