banano

banano

Hi guys!

I’m trying to upgrade the current library for phoenix socket client for elixir itself https://github.com/Aircloak/phoenix_gen_socket_client, which is more than a year old and works for 1.3, but has several outdated things, like Poison dependency, cowboy, among others, and i can’t fix the tests.

It creates a generic base phoenix app, but fails to launch the endpoint:

     ** (EXIT from #PID<0.265.0>) shutdown: failed to start child: Phoenix.PubSub.PG2
         ** (EXIT) shutdown: failed to start child: Phoenix.PubSub.LocalSupervisor
             ** (EXIT) an exception was raised:
                 ** (ArgumentError) argument error
                     (stdlib) :ets.new(TestSite.Endpoint, [:set, :named_table, {:read_concurrency, true}])
                     (phoenix_pubsub) lib/phoenix/pubsub/local_supervisor.ex:24: Phoenix.PubSub.LocalSupervisor.init/1
                     (stdlib) supervisor.erl:295: :supervisor.init/1
                     (stdlib) gen_server.erl:374: :gen_server.init_it/2
                     (stdlib) gen_server.erl:342: :gen_server.init_it/6
                     (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

The weird thing is that i run on iex :ets.new(TestSite.Endpoint, [:set, :named_table, {:read_concurrency, true}]) and runs ok

this is the declaration of the testSite:

defmodule TestSite do
  @moduledoc false

  defmodule PubSub do
    @moduledoc false
    def start_link(), do: Registry.start_link(keys: :duplicate, name: TestSite.PubSub)

    def subscribe(subscriber_key), do: Registry.register(__MODULE__, subscriber_key, nil)

    def notify(subscriber_key, message) do
      __MODULE__
      |> Registry.lookup(subscriber_key)
      |> Enum.map(fn {pid, _value} -> pid end)
      |> Enum.each(&send(&1, message))
    end
  end

  defmodule Endpoint do
    @moduledoc false
    use Phoenix.Endpoint, otp_app: :phoenix_gen_socket_client

    socket("/test_socket", TestSite.Socket, websocket: true, longpoll: false)
    socket("/test_socket_updated", TestSite.SocketUpdated, websocket: true, longpoll: false)

    @doc false
    def init(:supervisor, config) do
      {:ok,
       Keyword.merge(
         config,
         https: false,
         http: [port: 29_876],
         secret_key_base: String.duplicate("abcdefgh", 8),
         debug_errors: false,
         server: true,
         pubsub: [adapter: Phoenix.PubSub.PG2, name: __MODULE__]
       )}
    end
  end
...

any clues?

Showing Posts 1 to 4

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

This probably means the endpoint is already started, or that there is at least an :ets table with that name already:

iex(1)> :ets.new(TestSite.Endpoint, [:set, :named_table, {:read_concurrency, true}])
TestSite.Endpoint
iex(2)> :ets.new(TestSite.Endpoint, [:set, :named_table, {:read_concurrency, true}])
** (ArgumentError) argument error
    (stdlib) :ets.new(TestSite.Endpoint, [:set, :named_table, {:read_concurrency, true}])

Maybe that helps point you in the right direction?

banano

banano OP

I checked ets tables right before start, and there’s no table with that name:

the endpoint:

  defmodule Endpoint do
    @moduledoc false
    use Phoenix.Endpoint, otp_app: :phoenix_gen_socket_client

    socket("/test_socket", TestSite.Socket, websocket: true, longpoll: false)
    socket("/test_socket_updated", TestSite.SocketUpdated, websocket: true, longpoll: false)

    @doc false
    def init(:supervisor, config) do
      IO.inspect(:ets.all |> Enum.filter(fn x -> is_atom(x) end))
      {:ok,
       Keyword.merge(
         config,
         https: false,
         http: [port: 29_876],
         secret_key_base: String.duplicate("abcdefgh", 8),
         debug_errors: false,
         server: true,
         pubsub: [adapter: Phoenix.PubSub.PG2, name: __MODULE__]
       )}
    end
  end

the test results:

phoenix_gen_socket_client % mix test
Compiling 1 file (.ex)
[:telemetry_handler_table, :ssl_pem_cache, :httpc_manager__session_db,
 :httpc_manager__handler_db, :hex_version, :httpc_hex__session_db,
 :httpc_hex__handler_db, TestSite.PubSub, ExUnit.OnExitHandler, :logger,
 :ac_tab, :inet_db, :inet_cache, :inet_hosts_byname, :inet_hosts_byaddr,
 :inet_hosts_file_byname, :inet_hosts_file_byaddr, :global_locks, :global_names,
 :global_names_ext, :global_pid_names, :global_pid_ids, :file_io_servers,
 :elixir_config, :elixir_modules, Plug.Keys, Plug.Upload, :ranch_server,
 :cowboy_clock]


  0) Phoenix.Channels.GenSocketClientTest: failure on setup_all callback, all tests have been invalidated
     ** (EXIT from #PID<0.265.0>) shutdown: failed to start child: Phoenix.PubSub.PG2
         ** (EXIT) shutdown: failed to start child: Phoenix.PubSub.LocalSupervisor
             ** (EXIT) an exception was raised:
                 ** (ArgumentError) argument error
                     (stdlib) :ets.new(TestSite.Endpoint, [:set, :named_table, {:read_concurrency, true}])
                     (phoenix_pubsub) lib/phoenix/pubsub/local_supervisor.ex:24: Phoenix.PubSub.LocalSupervisor.init/1
                     (stdlib) supervisor.erl:295: :supervisor.init/1
                     (stdlib) gen_server.erl:374: :gen_server.init_it/2
                     (stdlib) gen_server.erl:342: :gen_server.init_it/6
                     (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

If i remove the init() it doesn’t start at all.
Would be that Endpoint.start_link() isn’t the right way to start the endpoint without a supervisor anymore?

any other hint?

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Ah so for one thing, in a test, use start_supervised(Endpoint). This will ensure that the endpoint is shut down in the given test case before it is started in another test case. Can you show where you’re calling start_link right now?

banano

banano OP

same thing with start_supervised(Endpoint)

This is where it’s being called at Phoenix.Channels.GenSocketClientTest

  setup_all do
    ExUnit.CaptureLog.capture_log(fn -> Endpoint.start_link() end)
    #start_supervised(Endpoint)
    :ok
  end

this is the repo and the test file that i’m working on right now
https://github.com/naaano/phoenix_gen_socket_client/blob/jason/test/socket_client_test.exs

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews