Skip to content

Commit c76dcd1

Browse files
Sort topics in test
The issue is related to map key ordering changes introduced in OTP 26. Erlang made internal changes to optimize map operations by changing the internal sort order of atom keys. As stated in the Erlang OTP Release Notes: > Some map operations have been optimized by changing the internal sort order of atom keys. This changes the (undocumented) order of how atom keys in small maps are printed and returned. The new order is unpredictable and may change between different invocations of the Erlang VM. Elixir 1.14.4 acknowledged this change in its release notes: > When migrating to Erlang/OTP 26, keep in mind it changes how maps are stored internally and they will be printed and traversed in a different order (note maps never provided a guarantee of their order). The test was failing because it assumed a specific order of keys, but with OTP 26's changes, the order is now unpredictable and can be different between runs, and therefore I sorted the keys before comparison to get a deterministic test result.
1 parent 011e057 commit c76dcd1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

test/pub_sub_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ defmodule PubSubTest do
8383
PubSub.subscribe(pid, topic2)
8484
PubSub.subscribe(pid, topic3)
8585

86-
assert PubSub.topics() == [:elixir, :erlang, :opensource]
86+
assert Enum.sort(PubSub.topics()) == [:elixir, :erlang, :opensource]
8787
end
8888

8989
test "process can publish a message to a topic" do

0 commit comments

Comments
 (0)