Skip to content

Commit d35182b

Browse files
committed
Future proof test_util:fake_pid/1
in OTP 23 pids hava new type tag: 88 (previously 103). To account for this copy whatever the local pid returns and insert that in the output binary.
1 parent df5952a commit d35182b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

test/test_util.erl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,19 @@ fake_pid(Node) ->
1010
ThisNodeSize = size(term_to_binary(node())) + 1,
1111
Pid = spawn(fun () -> ok end),
1212
%% drop the local node data from a local pid
13-
<<_:ThisNodeSize/binary, LocalPidData/binary>> = term_to_binary(Pid),
13+
<<Pre:ThisNodeSize/binary, LocalPidData/binary>> = term_to_binary(Pid),
1414
S = size(NodeBin),
15+
%% get the encoding type of the pid
16+
<<_:8, Type:8/unsigned, _/binary>> = Pre,
1517
%% replace it with the incoming node binary
16-
Final = <<131,103, 100, S:16/unsigned, NodeBin/binary, LocalPidData/binary>>,
18+
Final = <<131, Type, 100, S:16/unsigned, NodeBin/binary, LocalPidData/binary>>,
1719
binary_to_term(Final).
20+
21+
-ifdef(TEST).
22+
-include_lib("eunit/include/eunit.hrl").
23+
24+
fake_pid_test() ->
25+
_ = fake_pid(banana),
26+
ok.
27+
28+
-endif.

0 commit comments

Comments
 (0)