-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Allow using socket/connect in another process. #5488
Conversation
5b2a84d
to
48c210f
Compare
lib/phoenix/test/channel_test.ex
Outdated
@@ -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__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
socket(nil, nil, [],[], __CALLER__) | |
socket(nil, nil, [], [], __CALLER__) |
lib/phoenix/test/channel_test.ex
Outdated
defmacro socket(id, assigns) do | ||
socket(nil, id, assigns, __CALLER__) | ||
socket(nil, id, assigns,[], __CALLER__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
socket(nil, id, assigns,[], __CALLER__) | |
socket(nil, id, assigns, [], __CALLER__) |
lib/phoenix/test/channel_test.ex
Outdated
@@ -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 |
There was a problem hiding this comment.
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
48c210f
to
cef59ef
Compare
💚 💙 💜 💛 ❤️ |
brought about by: phoenixframework/phoenix#5488 Removing the 3rd argument is backwards compatible since `connect_info` still defaults to `%{}`.
brought about by: phoenixframework/phoenix#5488 Removing the 3rd argument is backwards compatible since `connect_info` still defaults to `%{}`.
As proposed by @josevalim in #5326, I added an optional 4th argument to
socket/3
andconnect/3
thatallows to give the
pid
of the test process. This is needed when wanting to use the socket from aTask
orother process that is not your test.