Skip to content

Commit db8e7e9

Browse files
committed
Really fix those flaky tests
1 parent 82f73f8 commit db8e7e9

22 files changed

+149
-131
lines changed

lib/sentry/application.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule Sentry.Application do
2525
[Sentry.Transport.SenderPool]
2626

2727
cache_loaded_applications()
28-
Sources.load_source_code_map_if_present()
28+
_ = Sources.load_source_code_map_if_present()
2929

3030
Supervisor.start_link(children, strategy: :one_for_one, name: Sentry.Supervisor)
3131
end

lib/sentry/config.ex

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
defmodule Sentry.Config do
22
@moduledoc false
33

4-
@default_exclude_patterns [~r"/_build/", ~r"/deps/", ~r"/priv/", ~r"/test/"]
5-
@private_env_keys [:sender_pool_size]
6-
74
basic_opts_schema = [
85
dsn: [
96
type: {:or, [:string, nil]},
@@ -232,7 +229,7 @@ defmodule Sentry.Config do
232229
type:
233230
{:list,
234231
{:custom, __MODULE__, :__validate_struct__, [:source_code_exclude_patterns, Regex]}},
235-
default: @default_exclude_patterns,
232+
default: [~r"/_build/", ~r"/deps/", ~r"/priv/", ~r"/test/"],
236233
type_doc: "list of `t:Regex.t/0`",
237234
doc: """
238235
A list of regular expressions used to determine which files to
@@ -309,7 +306,6 @@ defmodule Sentry.Config do
309306
def validate!(config) when is_list(config) do
310307
config_opts =
311308
config
312-
|> Keyword.drop(@private_env_keys)
313309
|> Keyword.take(@valid_keys)
314310
|> fill_in_from_env(:dsn, "SENTRY_DSN")
315311
|> fill_in_from_env(:release, "SENTRY_RELEASE")
@@ -325,7 +321,8 @@ defmodule Sentry.Config do
325321

326322
{:error, error} ->
327323
raise ArgumentError, """
328-
invalid configuration for the :sentry application, so we cannot start it. The error was:
324+
invalid configuration for the :sentry application, so we cannot start or update
325+
its configuration. The error was:
329326
330327
#{Exception.message(error)}
331328
@@ -336,11 +333,9 @@ defmodule Sentry.Config do
336333

337334
@spec persist(keyword()) :: :ok
338335
def persist(config) when is_list(config) do
339-
for {key, value} <- config do
336+
Enum.each(config, fn {key, value} ->
340337
:persistent_term.put({:sentry_config, key}, value)
341-
end
342-
343-
:ok
338+
end)
344339
end
345340

346341
@spec docs() :: String.t()
@@ -370,10 +365,6 @@ defmodule Sentry.Config do
370365
"""
371366
end
372367

373-
# Also exposed as a function to be used in docs in the Sentry module.
374-
@spec default_source_code_exclude_patterns() :: [Regex.t(), ...]
375-
def default_source_code_exclude_patterns, do: @default_exclude_patterns
376-
377368
@spec dsn() :: String.t() | nil
378369
def dsn, do: get(:dsn)
379370

@@ -460,27 +451,20 @@ defmodule Sentry.Config do
460451

461452
@spec put_config(atom(), term()) :: :ok
462453
def put_config(key, value) when is_atom(key) do
463-
case NimbleOptions.validate([{key, value}], @opts_schema) do
464-
{:ok, options} ->
465-
renamed_key =
466-
case key do
467-
:before_send_event -> :before_send
468-
other -> other
469-
end
470-
471-
options
472-
|> handle_deprecated_before_send()
473-
|> Keyword.take([renamed_key])
474-
|> persist()
475-
476-
{:error, error} ->
477-
raise ArgumentError, """
478-
invalid configuration to update. The error was:
454+
unless key in @valid_keys do
455+
raise ArgumentError, "unknown option #{inspect(key)}"
456+
end
479457

480-
#{Exception.message(error)}
458+
renamed_key =
459+
case key do
460+
:before_send_event -> :before_send
461+
other -> other
462+
end
481463

482-
"""
483-
end
464+
[{key, value}]
465+
|> validate!()
466+
|> Keyword.take([renamed_key])
467+
|> persist()
484468
end
485469

486470
## Helpers

lib/sentry/sources.ex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,34 @@ defmodule Sentry.Sources do
1111

1212
@source_code_map_key {:sentry, :source_code_map}
1313

14-
@spec load_source_code_map_if_present() :: :ok
14+
@spec load_source_code_map_if_present() :: :loaded | {:error, term()}
1515
def load_source_code_map_if_present do
1616
path = Path.relative_to_cwd(path_of_packaged_source_code())
1717

1818
with {:ok, contents} <- File.read(path),
1919
{:ok, source_map} <- decode_source_code_map(contents) do
2020
:persistent_term.put(@source_code_map_key, source_map)
21+
{:loaded, source_map}
2122
else
2223
{:error, :binary_to_term} ->
2324
IO.warn("""
2425
Sentry found a source code map file at #{path}, but it was unable to decode its
2526
contents.
2627
""")
2728

29+
{:error, :decoding_error}
30+
2831
{:error, :enoent} ->
29-
:ok
32+
{:error, :enoent}
3033

3134
{:error, reason} ->
3235
IO.warn("""
3336
Sentry found a source code map file at #{path}, but it was unable to read it.
3437
The reason was: #{:file.format_error(reason)}
3538
""")
36-
end
3739

38-
:ok
40+
{:error, reason}
41+
end
3942
end
4043

4144
@spec path_of_packaged_source_code() :: Path.t()
@@ -65,8 +68,9 @@ defmodule Sentry.Sources do
6568
:persistent_term.get(@source_code_map_key, nil)
6669
end
6770

68-
@spec load_files([Path.t()]) :: {:ok, source_map()} | {:error, message :: String.t()}
69-
def load_files(root_paths \\ Config.root_source_code_paths()) when is_list(root_paths) do
71+
@spec load_files([Path.t()] | nil) :: {:ok, source_map()} | {:error, message :: String.t()}
72+
def load_files(root_paths \\ nil) do
73+
root_paths = root_paths || Config.root_source_code_paths()
7074
path_pattern = Config.source_code_path_pattern()
7175
exclude_patterns = Config.source_code_exclude_patterns()
7276

mix.exs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ defmodule Sentry.Mixfile do
5757
],
5858
authors: ["Mitchell Henke", "Jason Stiebs", "Andrea Leopardi"]
5959
],
60-
xref: [exclude: [:hackney, :hackney_pool, Plug.Conn]]
60+
xref: [exclude: [:hackney, :hackney_pool, Plug.Conn]],
61+
aliases: [aliases()]
6162
]
6263
end
6364

@@ -107,4 +108,8 @@ defmodule Sentry.Mixfile do
107108
}
108109
]
109110
end
111+
112+
defp aliases do
113+
[test: ["sentry.package_source_code", "test"]]
114+
end
110115
end

test/context_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule Sentry.ContextTest do
2-
use ExUnit.Case, async: false
2+
use Sentry.Case, async: false
33

44
import Sentry.TestHelpers
55

test/envelope_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule Sentry.EnvelopeTest do
2-
use ExUnit.Case, async: false
2+
use Sentry.Case, async: false
33

44
import Sentry.TestHelpers
55

test/event_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule Sentry.EventTest do
2-
use ExUnit.Case, async: false
2+
use Sentry.Case, async: false
33

44
import Sentry.TestHelpers
55

test/logger_backend_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule Sentry.LoggerBackendTest do
2-
use ExUnit.Case, async: false
2+
use Sentry.Case, async: false
33

44
import Sentry.TestHelpers
55

test/mix/sentry.package_source_code_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule Mix.Tasks.Sentry.PackageSourceCodeTest do
2-
use ExUnit.Case, async: false
2+
use Sentry.Case, async: false
33

44
import Sentry.TestHelpers
55

test/mix/sentry.send_test_event_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule Mix.Tasks.Sentry.SendTestEventTest do
2-
use ExUnit.Case
2+
use Sentry.Case
33

44
import ExUnit.CaptureIO
55
import Sentry.TestHelpers

0 commit comments

Comments
 (0)