From 46625c4dfba3eb84c8f7fdea12ced77ad8f1b0a8 Mon Sep 17 00:00:00 2001 From: Andrew Dryga Date: Tue, 14 May 2024 10:56:59 -0600 Subject: [PATCH] Fix flaky tests --- test/logger_json/formatter/message_test.exs | 6 +++--- test/logger_json/formatters/datadog_test.exs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/logger_json/formatter/message_test.exs b/test/logger_json/formatter/message_test.exs index a393db4..10c4b44 100644 --- a/test/logger_json/formatter/message_test.exs +++ b/test/logger_json/formatter/message_test.exs @@ -6,7 +6,7 @@ defmodule LoggerJSON.Formatter.MessageTest do setup do # Define mock formatters binary_fmt = fn data -> "Binary: #{data}" end - structured_fmt = fn data -> "Structured: #{inspect(data)}" end + structured_fmt = fn data -> "Structured: #{data |> Enum.sort() |> inspect()}" end crash_fmt = fn message, reason -> "Crash: #{message} - #{reason}" end {:ok, formatters: %{binary: binary_fmt, structured: structured_fmt, crash: crash_fmt}} @@ -29,7 +29,7 @@ defmodule LoggerJSON.Formatter.MessageTest do meta = %{} assert format_message(message, meta, %{structured: formatters.structured}) == - "Structured: %{id: 1, content: \"Report data\"}" + ~s|Structured: [content: "Report data", id: 1]| end test "formats reports with custom callbacks altering the data", %{formatters: formatters} do @@ -51,7 +51,7 @@ defmodule LoggerJSON.Formatter.MessageTest do test "formats report with default behavior", %{formatters: formatters} do message = {:report, %{id: 2, content: "Another report"}} meta = %{report_cb: &:logger.format_otp_report/1} - assert format_message(message, meta, formatters) == "Structured: %{id: 2, content: \"Another report\"}" + assert format_message(message, meta, formatters) == ~s|Structured: [content: "Another report", id: 2]| end test "formats general message using Logger.Utils.scan_inspect", %{formatters: formatters} do diff --git a/test/logger_json/formatters/datadog_test.exs b/test/logger_json/formatters/datadog_test.exs index 402b38e..bf05c8d 100644 --- a/test/logger_json/formatters/datadog_test.exs +++ b/test/logger_json/formatters/datadog_test.exs @@ -346,7 +346,7 @@ defmodule LoggerJSON.Formatters.DatadogTest do assert %{ "error" => %{"message" => "error here"}, "logger" => %{ - "file_name" => "/Users/andrew/Projects/os/logger_json/test/logger_json/formatters/datadog_test.exs", + "file_name" => _file, "line" => _line, "method_name" => "Elixir.LoggerJSON.Formatters.DatadogTest." <> _, "thread_name" => _pid @@ -366,7 +366,7 @@ defmodule LoggerJSON.Formatters.DatadogTest do assert %{ "error" => %{"message" => "error here"}, "logger" => %{ - "file_name" => "/Users/andrew/Projects/os/logger_json/test/logger_json/formatters/datadog_test.exs", + "file_name" => _file, "line" => _line, "method_name" => "Elixir.LoggerJSON.Formatters.DatadogTest." <> _, "thread_name" => _pid @@ -386,7 +386,7 @@ defmodule LoggerJSON.Formatters.DatadogTest do assert %{ "error" => %{"message" => "error here"}, "logger" => %{ - "file_name" => "/Users/andrew/Projects/os/logger_json/test/logger_json/formatters/datadog_test.exs", + "file_name" => _file, "line" => _line, "method_name" => "Elixir.LoggerJSON.Formatters.DatadogTest." <> _, "thread_name" => _pid @@ -406,7 +406,7 @@ defmodule LoggerJSON.Formatters.DatadogTest do assert %{ "error" => %{"message" => "error here"}, "logger" => %{ - "file_name" => "/Users/andrew/Projects/os/logger_json/test/logger_json/formatters/datadog_test.exs", + "file_name" => _file, "line" => _line, "method_name" => "Elixir.LoggerJSON.Formatters.DatadogTest." <> _, "thread_name" => _pid