Skip to content

Commit

Permalink
Silence mnesia events
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultzer committed Feb 7, 2024
1 parent 2756da9 commit 5914d8b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/pow/store/backend/mnesia_cache_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ defmodule Pow.Store.Backend.MnesiaCacheTest do
start_supervised!(MnesiaCache)
:mnesia.subscribe(:system)
:mnesia.subscribe({:table, MnesiaCache, :simple})

# Silence Mnesia events
if :global.whereis_name(:mnesia_global_logger) == :undefined,
do: :yes = :global.register_name(:mnesia_global_logger, self())
end

defp restart do
Expand Down Expand Up @@ -631,6 +635,12 @@ defmodule Pow.Store.Backend.MnesiaCacheTest do
{:noreply, state}
end

# Drown Mnesia events io format
# Mnesia process handler
def handle_info({:io_request, _pid, _ref, _}, state) do
{:noreply, state}
end

# GenServer handler
def handle_info(event, {event_mgr_ref, parent}) do
send_event(event_mgr_ref, parent, event)
Expand Down Expand Up @@ -670,7 +680,10 @@ defmodule Pow.Store.Backend.MnesiaCacheTest do
end

defp listen(node, module) when module in [:mnesia, :node] do
{:ok, _} = :rpc.call(node, Supervisor, :start_child, [Pow.Supervisor, {Pow.Test.Listener, {module, self()}}])
{:ok, pid} = :rpc.call(node, Supervisor, :start_child, [Pow.Supervisor, {Pow.Test.Listener, {module, self()}}])

if rpc(node, :global, :whereis_name, [:mnesia_global_logger]) == :undefined,
do: :yes = rpc(node, :global, :register_name, [:mnesia_global_logger, pid])
end
defp listen(node, Logger) do
:ok = :gen_event.add_handler({Logger, node}, Pow.Test.Listener, {Logger, self()})
Expand Down Expand Up @@ -728,6 +741,7 @@ defmodule Pow.Store.Backend.MnesiaCacheTest do
rpc(node, Supervisor, :terminate_child, [Pow.Supervisor, MnesiaCache.Unsplit])
rpc(node, Supervisor, :terminate_child, [Pow.Supervisor, MnesiaCache])
rpc(node, :mnesia, :stop, [])
:ok = rpc(node, :global, :unregister_name, [:mnesia_global_logger])

:peer.stop(pid)

Expand Down

0 comments on commit 5914d8b

Please sign in to comment.