From 52d38f1788f11dfb0b7e55ec694258cdce012374 Mon Sep 17 00:00:00 2001 From: Jack Mordaunt Date: Thu, 12 Jun 2025 17:15:09 -0300 Subject: test/core/sync/chan: serialize try_select tests These tests will race access to __global_context_for_test, which can cause the test suite to flake. Even though only a single test actually references the variable, the logic in try_select consumes it. --- tests/core/sync/chan/test_core_sync_chan.odin | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/core/sync/chan/test_core_sync_chan.odin b/tests/core/sync/chan/test_core_sync_chan.odin index e8bb553b1..608d0c3d2 100644 --- a/tests/core/sync/chan/test_core_sync_chan.odin +++ b/tests/core/sync/chan/test_core_sync_chan.odin @@ -35,6 +35,10 @@ MAX_RAND :: 32 FAIL_TIME :: 1 * time.Second SLEEP_TIME :: 1 * time.Millisecond +// Synchronizes try_select tests that require access to global state. +test_lock: sync.Mutex +__global_context_for_test: rawptr + comm_client :: proc(th: ^thread.Thread) { data := cast(^Comm)th.data manual_buffering := data.manual_buffering @@ -277,6 +281,7 @@ test_accept_message_from_closed_buffered_chan :: proc(t: ^testing.T) { // operation will process it. @test test_try_select_raw_happy :: proc(t: ^testing.T) { + sync.guard(&test_lock) testing.set_fail_timeout(t, FAIL_TIME) recv1, recv1_err := chan.create(chan.Chan(int), context.allocator) @@ -348,6 +353,7 @@ test_try_select_raw_happy :: proc(t: ^testing.T) { // try_select_raw operation does not block. @test test_try_select_raw_default_state :: proc(t: ^testing.T) { + sync.guard(&test_lock) testing.set_fail_timeout(t, FAIL_TIME) recv1, recv1_err := chan.create(chan.Chan(int), context.allocator) @@ -374,6 +380,7 @@ test_try_select_raw_default_state :: proc(t: ^testing.T) { // thread between calls to can_{send,recv} and try_{send,recv}_raw. @test test_try_select_raw_no_toctou :: proc(t: ^testing.T) { + sync.guard(&test_lock) testing.set_fail_timeout(t, FAIL_TIME) // Trigger will be used to coordinate between the thief and the try_select. @@ -382,9 +389,6 @@ test_try_select_raw_no_toctou :: proc(t: ^testing.T) { assert(trigger_err == nil, "allocation failed") defer chan.destroy(trigger) - @(static) - __global_context_for_test: rawptr - __global_context_for_test = &trigger defer __global_context_for_test = nil -- cgit v1.2.3