diff options
Diffstat (limited to 'deps/rabbit/test/test_util.erl')
-rw-r--r-- | deps/rabbit/test/test_util.erl | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/deps/rabbit/test/test_util.erl b/deps/rabbit/test/test_util.erl new file mode 100644 index 0000000000..9a82b0ea1c --- /dev/null +++ b/deps/rabbit/test/test_util.erl @@ -0,0 +1,28 @@ +-module(test_util). + +-export([ + fake_pid/1 + ]). + + +fake_pid(Node) -> + NodeBin = rabbit_data_coercion:to_binary(Node), + ThisNodeSize = size(term_to_binary(node())) + 1, + Pid = spawn(fun () -> ok end), + %% drop the local node data from a local pid + <<Pre:ThisNodeSize/binary, LocalPidData/binary>> = term_to_binary(Pid), + S = size(NodeBin), + %% get the encoding type of the pid + <<_:8, Type:8/unsigned, _/binary>> = Pre, + %% replace it with the incoming node binary + Final = <<131, Type, 100, S:16/unsigned, NodeBin/binary, LocalPidData/binary>>, + binary_to_term(Final). + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +fake_pid_test() -> + _ = fake_pid(banana), + ok. + +-endif. |