dexcord/test/support/test_handler.ex
Luna 12689862c8 feat(gateway): phase 2 reliability core (resume/zombie/backoff/fatal) + FakeGateway
- fix heartbeat timer loss in :hello_wait (re-arm during identify-gap wait)
- honor server op 1 in :identifying/:hello_wait, not just :connected/:resuming
- full op 9 handling: d:false in :resuming re-IDENTIFYs on the same socket after
  the mandated 1-5s; d:false elsewhere floors the reconnect; d:true keeps session
- resume-loop cap (5 consecutive failed resumes -> fresh IDENTIFY) via Session ETS
- explicit conn_gen/stale-socket guard backstopping Mint's :unknown
- bounded TCP connect + configurable handshake watchdogs so a stalled reconnect
  self-heals instead of wedging
- FakeGateway scripted Bandit/WebSock test server + TestHandler
- integration suite (happy/zombie/kill/close-codes/op7/op9/replay/cap/backoff/gap/
  stale), fatal-path end-to-end, and unit tests for resume counter + backoff math
2026-07-04 00:09:33 -03:00

21 lines
614 B
Elixir

defmodule Dexcord.FakeGateway.TestHandler do
@moduledoc false
# A `Dexcord.Handler` that relays every dispatched event to a subscribed test
# process as `{:handler_event, {name, data}}`. The sink pid lives in
# `:persistent_term` so the stateless handler module can find it; each test calls
# `subscribe/1` in setup.
@behaviour Dexcord.Handler
@key {__MODULE__, :sink}
def subscribe(pid), do: :persistent_term.put(@key, pid)
@impl true
def handle_event(event) do
case :persistent_term.get(@key, nil) do
nil -> :ok
pid -> send(pid, {:handler_event, event})
end
end
end