aboutsummaryrefslogtreecommitdiff
path: root/tests/core/sync
Commit message (Collapse)AuthorAgeFilesLines
* Fix early join after start.Jeroen van Rijn2025-06-211-1/+1
|
* uncomment test, see if it's fixedLaytan Laats2025-06-201-3/+0
|
* Merge pull request #5329 from JackMordaunt/jfm-fix_chan_try_sendLaytan2025-06-201-47/+272
|\ | | | | chan: fix try_send and send
| * tests/core/sync/chan: test concurrent send/close/recvJack Mordaunt2025-06-131-0/+55
| | | | | | | | | | | | This test is designed to ensure that a call to send will always correctly report whether the value was transmitted. If recv wins, a close call should not be able to intercept the send thread.
| * core/sync/chan.send: return false if channel is closed while blockedJack Mordaunt2025-06-121-0/+44
| | | | | | | | | | | | | | | | | | | | | | | | This commit makes send behave the same as recv: that the call will return false if the channel is closed while a thread is waiting on the blocking operation. Prior logic would have send return true even if the channel was actually closed rather than read from. Docs adjusted to make this clear. Tests added to lock in this behaviour.
| * tests/core/sync/chan: add test for contended try_sendJack Mordaunt2025-06-121-0/+149
| | | | | | | | | | | | This test ensures that contending threads racing to try_send against a single blocking read will result in exactly one winner without any senders blocking.
| * core/sync/chan.try_send: avoid blocking if no reader is availableJack Mordaunt2025-06-121-44/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes the semantics of try_send to be consistently non-blocking. That is, if the buffered is full OR there are no readers it returns false. The previous behaviour was such that it would block in the latter case of no reader, and it would wait for a reader. That is problematic because it produces inconsistent behaviour between buffered and unbuffered channels which is astonishing and adds complexity to the caller. To illustrate the problem with the old behaviour, consider the try_select operation: if a send-channel happens to be unbuffered the try_select (which wants to never block) can now block, that unbuffered send channel is selected (at random) and there is no reader on the other side. Thus we have unpredictable blocking behaviour, which breaks the guarantee that try_select never blocks. If you want a blocking send you can just call "send" (the blocking variant). In addition, there is some reader/writer math done inside can_{send,recv} such that they only report true if there is sufficient reader/writer capacity. If there is contention we need to ensure that each reader is paired to exactly one writer. Consider try_send: if there is a single reader we can send. If there is a single reader and a single writer, then we cannot send, as that reader will be paired with the existing writer. Therefore can_send is only true if there are more readers than writers at the time of check. NOTE: The original tests don't need to use wait-looping with thread.yield() or heuristic sleep. Instead we can just use blocking channel operations rather than non-blocking operations.
| * test/core/sync/chan: serialize try_select testsJack Mordaunt2025-06-121-3/+7
| | | | | | | | | | | | 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.
* | Disable test_try_select_raw_happyJeroen van Rijn2025-06-161-0/+3
|/
* tests/core/sync/chan: move global state into testJack Mordaunt2025-06-121-2/+3
| | | | | While this state is not actually needed by more than one test, we can just make it a static variable.
* tests/core/sync/chan: test harness for chan.try_select_rawJack Mordaunt2025-06-121-0/+176
| | | | | | | | This test harness ensures consistent non-blocking semantics and validates that we have solved the toctou condition. The __global_context_for_test is a bit of a hack to fuse together the test supplied proc and the executing logic in packaage chan.
* Remove comment from core sync tests now that they're fixedpkova2024-09-171-3/+0
|
* Fix core sync test deadlock on darwinpkova2024-09-171-1/+0
|
* Add tests for `core:sync` and `core:sync/chan`Feoramund2024-09-112-0/+992