Skip to content

Commit

Permalink
Fix race condition in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewDryga committed May 14, 2024
1 parent 7a52b45 commit fdb13e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/logger_json/formatters/basic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule LoggerJSON.Formatters.Basic do
line =
%{
time: utc_time(meta),
severity: Atom.to_string(level) |> String.downcase(),
severity: Atom.to_string(level),
message: encode(message, redactors),
metadata: encode(take_metadata(meta, metadata_selector), redactors)
}
Expand Down
8 changes: 6 additions & 2 deletions test/logger_json/ecto_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ defmodule LoggerJSON.EctoTest do
import LoggerJSON.Ecto
require Logger

setup do
formatter = {LoggerJSON.Formatters.Basic, metadata: :all}
:logger.update_handler_config(:default, :formatter, formatter)
end

describe "telemetry_logging_handler/4" do
test "logs ecto queries received via telemetry event" do
log =
Expand Down Expand Up @@ -43,8 +48,7 @@ defmodule LoggerJSON.EctoTest do
"queue_time_μs" => 106,
"repo" => "Repo"
}
},
"severity" => "info"
}
} = decode_or_print_error(log)
end

Expand Down
8 changes: 6 additions & 2 deletions test/logger_json/plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ defmodule LoggerJSON.PlugTest do
import LoggerJSON.Plug
require Logger

setup do
formatter = {LoggerJSON.Formatters.Basic, metadata: :all}
:logger.update_handler_config(:default, :formatter, formatter)
end

describe "telemetry_logging_handler/4" do
test "logs request latency and metadata" do
conn = Plug.Test.conn(:get, "/")
Expand All @@ -25,8 +30,7 @@ defmodule LoggerJSON.PlugTest do
"request" => %{
"client" => %{"ip" => "127.0.0.1", "user_agent" => nil},
"connection" => %{"method" => "GET", "path" => "/", "protocol" => "HTTP/1.1", "status" => nil}
},
"severity" => "info"
}
} = decode_or_print_error(log)
end

Expand Down

0 comments on commit fdb13e5

Please sign in to comment.