Skip to content

Commit

Permalink
chore: reduce testing log level
Browse files Browse the repository at this point in the history
  • Loading branch information
tlux committed Mar 28, 2024
1 parent bf3097f commit c5a271c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 2 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Config

config :logger, level: :info

config :graphql_ws_client, GraphQLWSClient.TestClient,
url: "ws://localhost:8080/subscriptions",
driver: {GraphQLWSClient.Drivers.Gun, connect_options: [connect_timeout: 500]}
17 changes: 10 additions & 7 deletions lib/graphql_ws_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ defmodule GraphQLWSClient do

@impl true
def connect(info, %State{config: config} = state) do
Logger.info(
Logger.debug(
format_log(
"Connecting to #{config.host}:#{config.port} at #{config.path}"
)
Expand All @@ -436,7 +436,7 @@ defmodule GraphQLWSClient do
Connection.reply(from, :ok)
end

Logger.info(format_log("Connected"))
Logger.debug(format_log("Connected"))

resubscribe_listeners(conn, state.listeners)

Expand Down Expand Up @@ -474,7 +474,7 @@ defmodule GraphQLWSClient do
def disconnect({:error, error}, %State{} = state) do
state = close_connection(state)

Logger.info(format_log("Disconnected, reconnecting..."))
Logger.debug(format_log("Disconnected, reconnecting..."))

flush_queries_with_error(state.queries, error)

Expand All @@ -484,7 +484,10 @@ defmodule GraphQLWSClient do
@impl true
def terminate(reason, %State{} = state) do
Logger.debug(
format_log("Terminating client, closing connection: #{inspect(reason)}")
format_log(
"Terminating client, closing connection " <>
"(reason: #{inspect(reason)})"
)
)

close_connection(state)
Expand Down Expand Up @@ -596,10 +599,10 @@ defmodule GraphQLWSClient do
def handle_info({:DOWN, ref, :process, _pid, reason}, %State{} = state) do
case State.fetch_listener_by_monitor(state, ref) do
{:ok, %State.Listener{id: id, pid: pid}} ->
Logger.info(
Logger.debug(
format_log(
"Subscription #{id} removed as listener process " <>
"#{inspect(pid)} went down with reason #{inspect(reason)}"
"Subscription #{id} removed as listener " <>
"#{inspect(pid)} went down (reason: #{inspect(reason)})"
)
)

Expand Down
14 changes: 3 additions & 11 deletions test/graphql_ws_client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,6 @@ defmodule GraphQLWSClientTest do
config = %{@config | query_timeout: 200}
conn = %{@conn | config: config}

stub(MockDriver, :disconnect, fn _ -> :ok end)

MockDriver
|> expect(:connect, fn _ -> {:ok, conn} end)
|> expect(:push_message, fn _, %Message{id: id} ->
Expand Down Expand Up @@ -499,8 +497,6 @@ defmodule GraphQLWSClientTest do
test "timeout" do
test_pid = self()

stub(MockDriver, :disconnect, fn _ -> :ok end)

MockDriver
|> expect(:connect, fn _ -> {:ok, @conn} end)
|> expect(:push_message, fn _, %Message{id: id} ->
Expand Down Expand Up @@ -1100,14 +1096,10 @@ defmodule GraphQLWSClientTest do
listener: listener,
subscription_id: subscription_id
} do
assert capture_log(fn ->
Process.exit(listener, :kill)
Process.exit(listener, :kill)

# wait until the subscription is actually removed
Process.sleep(100)
end) =~
"Subscription #{subscription_id} removed as listener " <>
"process #{inspect(listener)} went down"
# wait until the subscription is actually removed
Process.sleep(100)

refute Map.has_key?(get_state(client).listeners, subscription_id)
end
Expand Down

0 comments on commit c5a271c

Please sign in to comment.