erlang: send_after to registered name + gen_server timeout returns (T5+T6, 771/771)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 33s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 33s
T5 — send_after addresses a registered atom name; the delayed message
lands in that process's mailbox (destination resolved at fire time,
dead/unregistered targets drop silently).
T6 — gen_server loop now handles the {reply,R,S,T} / {noreply,S,T}
timeout-bearing callback returns by scheduling {timeout} to itself via
send_after; handle_info({timeout}, S) fires when no other message
arrives first. Sanity-checks the library hookup.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -118,3 +118,46 @@
|
||||
erlang:cancel_timer(Ref)")
|
||||
:name)
|
||||
"false")
|
||||
|
||||
;; ── T5 — send_after to a registered atom name ──────────────────────
|
||||
;; A second process registers itself as `srv`; the timer addresses it
|
||||
;; by name, and the delayed message lands in that process's mailbox.
|
||||
;; The server forwards what it got back to the parent for inspection.
|
||||
(er-sa-test
|
||||
"T5 timer delivers to registered name"
|
||||
(get
|
||||
(sa-ev
|
||||
"Me = self(),
|
||||
Pid = spawn(fun () -> receive M -> Me ! {got, M} end end),
|
||||
register(srv, Pid),
|
||||
erlang:send_after(20, srv, ping),
|
||||
receive {got, X} -> X end")
|
||||
:name)
|
||||
"ping")
|
||||
|
||||
;; ── T6 — gen_server {noreply, State, Timeout} hookup ───────────────
|
||||
;; A gen_server that, on the `arm` cast, returns {noreply, S, 100}.
|
||||
;; The library schedules {timeout} to itself via send_after; when no
|
||||
;; other message arrives first, handle_info({timeout}, S) fires. The
|
||||
;; handler signals the parent so we can confirm the timeout landed.
|
||||
(do
|
||||
(er-load-gen-server!)
|
||||
(erlang-load-module
|
||||
"-module(sa_tmo).
|
||||
init(Me) -> {ok, Me}.
|
||||
handle_call(_R, _F, S) -> {reply, ok, S}.
|
||||
handle_cast(arm, Me) -> {noreply, Me, 100}.
|
||||
handle_info({timeout}, Me) -> Me ! fired, {noreply, Me};
|
||||
handle_info(_M, S) -> {noreply, S}.")
|
||||
nil)
|
||||
|
||||
(er-sa-test
|
||||
"T6 gen_server timeout fires handle_info"
|
||||
(get
|
||||
(sa-ev
|
||||
"Me = self(),
|
||||
P = gen_server:start_link(sa_tmo, Me),
|
||||
gen_server:cast(P, arm),
|
||||
receive fired -> ok after 5000 -> timeout end")
|
||||
:name)
|
||||
"ok")
|
||||
|
||||
Reference in New Issue
Block a user