I’ve been trying to write a unit test for an FSM, that makes a call to a gen_server:
Result = gen_server:call(Pid, foo).
I wanted to fake the response to the call, without needing to spin up a gen_server instance. My first attempt didn’t really get me anywhere:
Result = ok, Pid = spawn(fun() -> receive _ -> Result end end).
But some digging through the OTP source revealed the solution:
Result = ok, Pid = spawn(fun() -> receive {_, {Caller, Ref}, _} -> Caller ! {Ref, Result} end end).