erlang: send_after deadline-ordering + cancel-of-fired tests (T3+T4, 769/769)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 45s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 45s
T3 — concurrent timers fire in deadline order, not schedule order (scheduler jumps the clock to the earliest pending deadline each time the runnable queue drains). T4 — cancel_timer on an already-fired timer returns the atom false. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -78,3 +78,43 @@
|
||||
receive late -> got after 50 -> none end")
|
||||
:name)
|
||||
"none")
|
||||
|
||||
;; ── T3 — multiple timers fire in deadline order, not schedule order ──
|
||||
;; `b` is scheduled first (deadline 80) but `a` second (deadline 20).
|
||||
;; Two plain receives drain the mailbox in arrival order — and arrival
|
||||
;; is governed by deadline, so the first message out is `a`.
|
||||
(er-sa-test
|
||||
"T3 timers fire in deadline order"
|
||||
(er-format-value
|
||||
(sa-ev
|
||||
"erlang:send_after(80, self(), b),
|
||||
erlang:send_after(20, self(), a),
|
||||
X = receive M1 -> M1 end,
|
||||
Y = receive M2 -> M2 end,
|
||||
{X, Y}"))
|
||||
"{a,b}")
|
||||
|
||||
;; A selective receive on `a` matches the earlier-deadline timer even
|
||||
;; though `b` was scheduled first.
|
||||
(er-sa-test
|
||||
"T3 selective receive picks earliest deadline"
|
||||
(get
|
||||
(sa-ev
|
||||
"erlang:send_after(80, self(), b),
|
||||
erlang:send_after(20, self(), a),
|
||||
receive a -> first end")
|
||||
:name)
|
||||
"first")
|
||||
|
||||
;; ── T4 — cancel_timer on an already-fired timer returns false ──────
|
||||
;; Once `x` has been received the timer has fired; cancelling its ref
|
||||
;; now yields the atom `false`.
|
||||
(er-sa-test
|
||||
"T4 cancel of fired timer is false"
|
||||
(get
|
||||
(sa-ev
|
||||
"Ref = erlang:send_after(20, self(), x),
|
||||
receive x -> ok end,
|
||||
erlang:cancel_timer(Ref)")
|
||||
:name)
|
||||
"false")
|
||||
|
||||
Reference in New Issue
Block a user