Hello,
I’m trying to test channels in a cluster of nodes using local-cluster.
Though it does not work when joining channel from the created nodes.
It fails with: socket/1-3 can only be invoked from the test process
Originally I had first seen that issue when testing channels outside of test process
Using test_process: pid
would solve it, though when used within Node.spawn, it does not
Here is a piece of code that reproduces the issue
setup_all do
{:ok, cluster} =
LocalCluster.start_link(3,
files: [
__ENV__.file
]
)
{:ok, nodes} = LocalCluster.nodes(cluster)
on_exit(fn ->
LocalCluster.stop(cluster)
end)
[nodes: nodes]
end
def newClient(userPK, topic, pid) do
socket =
MessagesWeb.UserSocket
|> socket("", %{user_id: userPK}, test_process: pid)
|> subscribe_and_join(
MessagesWeb.Room,
"rooms:#{topic}"
)
end
test "join channels in cluster", %{nodes: [node1, node2, node3]} do
pid = self()
users = 10000
{_n1_pid, ref} =
Node.spawn(node1, fn ->
map =
Enum.map(
1..users,
fn pk ->
Task.async(fn ->
socket = newClient(pk, "sf6", pid)
:timer.sleep(:timer.minutes(15))
end)
end
)
end)
end