Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using socket/connect in another process. #5488

Conversation

Hermanverschooten
Copy link
Contributor

As proposed by @josevalim in #5326, I added an optional 4th argument to socket/3 and connect/3 that
allows to give the pid of the test process. This is needed when wanting to use the socket from a Task or
other process that is not your test.

@Hermanverschooten Hermanverschooten force-pushed the allow_non_test_process_for_channel branch from 5b2a84d to 48c210f Compare June 15, 2023 17:01
@@ -276,13 +292,13 @@ defmodule Phoenix.ChannelTest do
@doc false
@deprecated "Phoenix.ChannelTest.socket/0 is deprecated, please call socket/1 instead"
defmacro socket() do
socket(nil, nil, [], __CALLER__)
socket(nil, nil, [],[], __CALLER__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
socket(nil, nil, [],[], __CALLER__)
socket(nil, nil, [], [], __CALLER__)

defmacro socket(id, assigns) do
socket(nil, id, assigns, __CALLER__)
socket(nil, id, assigns,[], __CALLER__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
socket(nil, id, assigns,[], __CALLER__)
socket(nil, id, assigns, [], __CALLER__)

@@ -291,21 +307,21 @@ defmodule Phoenix.ChannelTest do
Useful for testing UserSocket authentication. Returns
the result of the handler's `connect/3` callback.
"""
defmacro connect(handler, params, connect_info \\ quote(do: %{})) do
defmacro connect(handler, params, connect_info \\ quote(do: %{}), options \\ []) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find two optional arguments a smell, so what if we do this:

  defmacro connect(handler, params, options \\ quote(do: [])) do

And then __connect__ we do:

  {connect_info, options} =
    if is_map(options) do
      IO.warn("Passing \"connect_info\" directly to connect/3 is deprecated, please pass \"connect_info: ...\" as an option instead")
      {options, []}
    else
      Keyword.pop(options, :connect_info, %{})
    end

@Hermanverschooten Hermanverschooten force-pushed the allow_non_test_process_for_channel branch from 48c210f to cef59ef Compare June 16, 2023 03:48

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@josevalim josevalim merged commit a2b92c0 into phoenixframework:main Jun 16, 2023
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@Hermanverschooten Hermanverschooten deleted the allow_non_test_process_for_channel branch June 16, 2023 09:57
aptinio added a commit to aptinio/phoenix_live_view that referenced this pull request Jun 18, 2023
brought about by:
phoenixframework/phoenix#5488

Removing the 3rd argument is backwards compatible
since `connect_info` still defaults to `%{}`.
josevalim pushed a commit to phoenixframework/phoenix_live_view that referenced this pull request Jun 19, 2023
brought about by:
phoenixframework/phoenix#5488

Removing the 3rd argument is backwards compatible
since `connect_info` still defaults to `%{}`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants