Skip to content

Commit efae3a6

Browse files
authored
Speed up tests by ~450% (#690)
1 parent 452a26e commit efae3a6

File tree

8 files changed

+20
-18
lines changed

8 files changed

+20
-18
lines changed

config/config.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ if config_env() == :test do
66
tags: %{},
77
enable_source_code_context: true,
88
root_source_code_paths: [File.cwd!()],
9-
source_code_exclude_patterns: [],
109
hackney_opts: [recv_timeout: 50, pool: :sentry_pool],
1110
send_result: :sync,
1211
send_max_attempts: 1,

lib/sentry/sources.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ defmodule Sentry.Sources do
1010
}
1111

1212
@source_code_map_key {:sentry, :source_code_map}
13+
@compression_level if Mix.env() == :test, do: 0, else: 9
1314

1415
# Default argument is here for testing.
1516
@spec load_source_code_map_if_present(Path.t()) :: {:loaded, source_map()} | {:error, term()}
@@ -51,7 +52,7 @@ defmodule Sentry.Sources do
5152
def encode_source_code_map(%{} = source_map) do
5253
# This term contains no atoms, so that it can be decoded with binary_to_term(bin, [:safe]).
5354
term_to_encode = %{"version" => 1, "files_map" => source_map}
54-
:erlang.term_to_binary(term_to_encode, compressed: 9)
55+
:erlang.term_to_binary(term_to_encode, compressed: @compression_level)
5556
end
5657

5758
defp decode_source_code_map(binary) when is_binary(binary) do

test/context_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ defmodule Sentry.ContextTest do
7777
assert event.user == %{}
7878
end
7979

80-
@tag start_app: false
8180
test "passing in tags context as option overrides Context and Application config" do
8281
Context.set_tags_context(%{"key" => "345", "key1" => "123"})
8382
put_test_config(tags: %{"key" => "overridden", "key2" => "1234", "key3" => "12345"})

test/logger_backend_test.exs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,9 @@ defmodule Sentry.LoggerBackendTest do
126126

127127
ref = register_before_send()
128128

129-
{:ok, _plug_pid} = Plug.Cowboy.http(Sentry.ExamplePlugApplication, [], port: 8003)
130-
131129
:hackney.get("http://127.0.0.1:8003/error_route", [], "", [])
132130
assert_receive {^ref, _event}, 1000
133131
after
134-
:ok = Plug.Cowboy.shutdown(Sentry.ExamplePlugApplication.HTTP)
135132
Logger.configure_backend(Sentry.LoggerBackend, excluded_domains: [:cowboy])
136133
end
137134

@@ -312,7 +309,7 @@ defmodule Sentry.LoggerBackendTest do
312309

313310
Logger.error("Error", domain: [:sentry])
314311

315-
refute_receive {^ref, _event}
312+
refute_received {^ref, _event}
316313
end
317314

318315
test "sets event level to Logger message level" do

test/mix/sentry.package_source_code_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ defmodule Mix.Tasks.Sentry.PackageSourceCodeTest do
3232
end
3333

3434
test "supports the --debug option" do
35+
# Use a path pattern that doesn't match any files, to make this test as fast as
36+
# possible.
37+
old_root_source_code_paths = Application.get_env(:sentry, :root_source_code_paths)
38+
39+
on_exit(fn ->
40+
Application.put_env(:sentry, :root_source_code_paths, old_root_source_code_paths)
41+
end)
42+
43+
Application.put_env(:sentry, :root_source_code_paths, [])
44+
3545
assert :ok = Mix.Task.rerun("sentry.package_source_code", ["--debug"])
3646

3747
assert {:messages,

test/sentry/dedupe_test.exs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ defmodule Sentry.DedupeTest do
55
alias Sentry.Dedupe
66
alias Sentry.Event
77

8-
@ttl_millisec 25
9-
108
describe "insert/1" do
119
test "works correctly" do
1210
event = %Event{
@@ -25,8 +23,8 @@ defmodule Sentry.DedupeTest do
2523
# Now, we trigger a sweep after waiting for the TTL interval.
2624
# To ensure the :sweep message is processed, we use the trick
2725
# of asking the GenServer for its state (which is a sync call).
28-
Process.sleep(@ttl_millisec * 2)
29-
send(Dedupe, {:sweep, @ttl_millisec})
26+
Process.sleep(5)
27+
send(Dedupe, {:sweep, 0})
3028
_ = :sys.get_state(Dedupe)
3129

3230
# Now, it's :new again.

test/sentry/logger_handler_test.exs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,8 @@ defmodule Sentry.LoggerHandlerTest do
9191
@tag handler_config: %{excluded_domains: []}
9292
test "sends two errors when a Plug process crashes if cowboy domain is not excluded",
9393
%{sender_ref: ref} do
94-
{:ok, _plug_pid} = Plug.Cowboy.http(Sentry.ExamplePlugApplication, [], port: 8003)
95-
9694
:hackney.get("http://127.0.0.1:8003/error_route", [], "", [])
9795
assert_receive {^ref, _event}, 1000
98-
after
99-
:ok = Plug.Cowboy.shutdown(Sentry.ExamplePlugApplication.HTTP)
10096
end
10197
end
10298

@@ -109,7 +105,7 @@ defmodule Sentry.LoggerHandlerTest do
109105
assert_receive {^ref, event}
110106
assert event.message.formatted == "Testing error"
111107

112-
refute_receive {^ref, _event}, 100
108+
refute_received {^ref, _event}, 100
113109
end
114110

115111
@tag handler_config: %{capture_log_messages: true, level: :warning}
@@ -122,7 +118,7 @@ defmodule Sentry.LoggerHandlerTest do
122118
assert event.message.formatted == "Testing warning"
123119
assert event.level == :warning
124120

125-
refute_receive {^ref, _event}, 100
121+
refute_received {^ref, _event}
126122
end
127123

128124
@tag handler_config: %{capture_log_messages: true}
@@ -147,7 +143,7 @@ defmodule Sentry.LoggerHandlerTest do
147143
@tag handler_config: %{capture_log_messages: true}
148144
test "ignores log messages that are logged by Sentry itself", %{sender_ref: ref} do
149145
Logger.error("Sentry had an error", domain: [:sentry])
150-
refute_receive {^ref, _event}
146+
refute_received {^ref, _event}
151147
end
152148
end
153149

test/test_helper.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ File.rm_rf!(Sentry.Sources.path_of_packaged_source_code())
55
ExUnit.after_suite(fn _ ->
66
File.rm_rf!(Sentry.Sources.path_of_packaged_source_code())
77
end)
8+
9+
{:ok, _} = Plug.Cowboy.http(Sentry.ExamplePlugApplication, [], port: 8003)

0 commit comments

Comments
 (0)