ChannelTests fail after phoenix upgrade

Hi,

I’m upgrading my phoenix app to v1.4.9 and now the end is near but I’m struggling with my channel tests.

The app and the channels work after all changes, but the channel tests fail and I could not find anything about the error:

** (ArgumentError) no socket supervision tree found for ClubHomepage.UserSocket.
     
     Ensure your ClubHomepage.Web.Endpoint contains a socket mount, for example:
     
         socket "/socket", ClubHomepage.UserSocket,
           websocket: true,
           longpoll: true

The error points me to define my socket in my Endpoint, but this I did before.

Where is my mistake?

2 Likes

Using the socket builder without a module is deprecated (socket/2). We print a dep warning in such cases, but by using socket/3, you are passing the “users_socket” string as the socket module, which I believe is causing your error. Please try:

    {:ok, _, socket} =
-     socket("users_socket: #{user.id}", %{current_user: user}, %{})
+     socket(MyAppWeb.UserSocket, "users_socket: #{user.id}", %{current_user: user})
4 Likes

Thanks for your answer, but this I tried too in match_commitments_channel_test.exs
Note: Yes, I use "#{user.id}" in this line, but I tried "user_socket: #{user.id}" as second parameter in socket/3 too without success.

Here is the stacktrace to the error above, which I forgot to post yesterday. Sorry.

     stacktrace:
       (phoenix) lib/phoenix/socket/pool_supervisor.ex:17: Phoenix.Socket.PoolSupervisor.start_child/4
       (phoenix) lib/phoenix/channel/server.ex:38: Phoenix.Channel.Server.join/4
       (phoenix) lib/phoenix/test/channel_test.ex:377: Phoenix.ChannelTest.join/4
       test/club_homepage_web/channels/match_commitments_channel_test.exs:14: ClubHomepage.MatchCommitmentsChannelTest.__ex_unit_setup_1/1
       test/club_homepage_web/channels/match_commitments_channel_test.exs:1: ClubHomepage.MatchCommitmentsChannelTest.__ex_unit__/2
1 Like

This evening I tried to find a solution with socket/3 again. In addition I renamed some modules and moved a lot of files to be closer to the current file structure of a fresh initialized phoenix project, because I started to develop my app with phoenix 1.0.x years ago. Finally I commented out leave_socket/1 in my test files and now things are working again. Thank you anyway Chris for your hint.

1 Like