Skip to content

Instantly share code, notes, and snippets.

@jswanner
Created August 29, 2025 14:40
Show Gist options
  • Select an option

  • Save jswanner/ec081c173655425563e522851d3b281a to your computer and use it in GitHub Desktop.

Select an option

Save jswanner/ec081c173655425563e522851d3b281a to your computer and use it in GitHub Desktop.
Put Your $callers

Put your $callers

Mix.install([:flame, :plug, :req])

Section

defmodule Server do
  use GenServer

  def init(opts) do
    {callers, opts} = Keyword.pop!(opts, :callers)
    Process.put(:"$callers", callers)
    Req.request!(opts) # more likely this would be a Repo call, failing with Ecto sandbox
    {:ok, opts}
  end

  def start_link(opts) do
    callers = Process.get(:"$callers", [])
    opts = Keyword.put_new(opts, :callers, callers)
    GenServer.start_link(__MODULE__, opts)
  end
end

ExUnit.start(autorun: false)

defmodule ServerTest do
  use ExUnit.Case, async: true

  test "can start" do
    Req.Test.stub(__MODULE__, &Req.Test.text(&1, "ok"))
    _pid = start_supervised!({Server, plug: {Req.Test, __MODULE__}})
    # Req.Test.allow(__MODULE__, self(), pid)
  end
end

ExUnit.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment