/deps/rabbit/test/test_util.erl

https://github.com/rabbitmq/rabbitmq-server · Erlang · 28 lines · 19 code · 6 blank · 3 comment · 0 complexity · 18669e13d9e714af2f44815206ebb12c MD5 · raw file

  1. -module(test_util).
  2. -export([
  3. fake_pid/1
  4. ]).
  5. fake_pid(Node) ->
  6. NodeBin = rabbit_data_coercion:to_binary(Node),
  7. ThisNodeSize = size(term_to_binary(node())) + 1,
  8. Pid = spawn(fun () -> ok end),
  9. %% drop the local node data from a local pid
  10. <<Pre:ThisNodeSize/binary, LocalPidData/binary>> = term_to_binary(Pid),
  11. S = size(NodeBin),
  12. %% get the encoding type of the pid
  13. <<_:8, Type:8/unsigned, _/binary>> = Pre,
  14. %% replace it with the incoming node binary
  15. Final = <<131, Type, 100, S:16/unsigned, NodeBin/binary, LocalPidData/binary>>,
  16. binary_to_term(Final).
  17. -ifdef(TEST).
  18. -include_lib("eunit/include/eunit.hrl").
  19. fake_pid_test() ->
  20. _ = fake_pid(banana),
  21. ok.
  22. -endif.