aboutsummaryrefslogtreecommitdiff
path: root/tests/core
diff options
context:
space:
mode:
authorJack Mordaunt <jackmordaunt.dev@gmail.com>2025-06-12 17:15:09 -0300
committerJack Mordaunt <jackmordaunt.dev@gmail.com>2025-06-12 17:15:37 -0300
commit52d38f1788f11dfb0b7e55ec694258cdce012374 (patch)
tree6d4d2411500d8e0b8a0f4b89ed49d8b5cbcebf81 /tests/core
parentfc7fc4d5cdcdb8c67f422b04e8992a1fff966235 (diff)
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.
Diffstat (limited to 'tests/core')
-rw-r--r--tests/core/sync/chan/test_core_sync_chan.odin10
1 files changed, 7 insertions, 3 deletions
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