Skip to content

Commit 3b7e8dd

Browse files
committed
update remaining tests, increase default timeout
1 parent e87b946 commit 3b7e8dd

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

lib/sentry/config.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ defmodule Sentry.Config do
328328
],
329329
finch_request_opts: [
330330
type: :keyword_list,
331-
default: [receive_timeout: 50],
331+
default: [receive_timeout: 5000],
332332
doc: """
333333
Request options to be passed to `Finch.request/4`. These options control
334334
individual request behavior. Only applied if `:client` is set to

test/logger_backend_test.exs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ defmodule Sentry.LoggerBackendTest do
136136

137137
start_supervised!(Sentry.ExamplePlugApplication, restart: :temporary)
138138

139-
:hackney.get("http://127.0.0.1:8003/error_route", [], "", [])
139+
Finch.build(:get, "http://127.0.0.1:8003/error_route", [], "", [])
140+
|> Finch.request(Sentry.FinchClient)
141+
140142
assert_receive {^ref, _event}, 1000
141143
after
142144
Logger.configure_backend(Sentry.LoggerBackend, excluded_domains: [:cowboy, :bandit])
@@ -149,7 +151,9 @@ defmodule Sentry.LoggerBackendTest do
149151

150152
start_supervised!({Sentry.ExamplePlugApplication, server: :bandit}, restart: :temporary)
151153

152-
:hackney.get("http://127.0.0.1:8003/error_route", [], "", [])
154+
Finch.build(:get, "http://127.0.0.1:8003/error_route", [], "", [])
155+
|> Finch.request(Sentry.FinchClient)
156+
153157
assert_receive {^ref, _event}, 1000
154158
after
155159
Logger.configure_backend(Sentry.LoggerBackend, excluded_domains: [:cowboy, :bandit])

test/sentry/logger_handler_test.exs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ defmodule Sentry.LoggerHandlerTest do
9090

9191
test "TODO", %{sender_ref: ref} do
9292
start_supervised!(Sentry.ExamplePlugApplication, restart: :temporary)
93-
:hackney.get("http://127.0.0.1:8003/error_route", [], "", [])
93+
94+
Finch.build(:get, "http://127.0.0.1:8003/error_route", [], "", [])
95+
|> Finch.request(Sentry.FinchClient)
96+
9497
assert_receive {^ref, event}, 1000
9598
assert event.original_exception == %RuntimeError{message: "Error"}
9699
end
@@ -100,7 +103,8 @@ defmodule Sentry.LoggerHandlerTest do
100103
%{sender_ref: ref} do
101104
start_supervised!(Sentry.ExamplePlugApplication, restart: :temporary)
102105

103-
:hackney.get("http://127.0.0.1:8003/error_route", [], "", [])
106+
Finch.build(:get, "http://127.0.0.1:8003/error_route", [], "", [])
107+
|> Finch.request(Sentry.FinchClient)
104108

105109
assert_receive {^ref, event}, 1000
106110
assert event.original_exception == %RuntimeError{message: "Error"}
@@ -114,7 +118,8 @@ defmodule Sentry.LoggerHandlerTest do
114118
%{sender_ref: ref} do
115119
start_supervised!({Sentry.ExamplePlugApplication, server: :bandit}, restart: :temporary)
116120

117-
:hackney.get("http://127.0.0.1:8003/error_route", [], "", [])
121+
Finch.build(:get, "http://127.0.0.1:8003/error_route", [], "", [])
122+
|> Finch.request(Sentry.FinchClient)
118123

119124
assert_receive {^ref, _event}, 1000
120125
end

test/sentry/transport_test.exs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Sentry.TransportTest do
44
import Sentry.TestHelpers
55
import ExUnit.CaptureLog
66

7-
alias Sentry.{ClientError, Envelope, Event, HackneyClient, Transport}
7+
alias Sentry.{ClientError, Envelope, Event, FinchClient, Transport}
88

99
describe "encode_and_post_envelope/2" do
1010
setup do
@@ -16,14 +16,13 @@ defmodule Sentry.TransportTest do
1616
test "sends a POST request with the right headers and payload", %{bypass: bypass} do
1717
envelope = Envelope.from_event(Event.create_event(message: "Hello 1"))
1818

19-
Bypass.expect_once(bypass, fn conn ->
19+
Bypass.expect(bypass, fn conn ->
2020
assert {:ok, body, conn} = Plug.Conn.read_body(conn)
2121

2222
assert conn.method == "POST"
2323
assert conn.request_path == "/api/1/envelope/"
2424

2525
assert ["sentry-elixir/" <> _] = Plug.Conn.get_req_header(conn, "user-agent")
26-
assert ["application/octet-stream"] = Plug.Conn.get_req_header(conn, "content-type")
2726
assert [sentry_auth_header] = Plug.Conn.get_req_header(conn, "x-sentry-auth")
2827

2928
assert sentry_auth_header =~
@@ -34,7 +33,7 @@ defmodule Sentry.TransportTest do
3433
Plug.Conn.resp(conn, 200, ~s<{"id":"123"}>)
3534
end)
3635

37-
assert {:ok, "123"} = Transport.encode_and_post_envelope(envelope, HackneyClient)
36+
assert {:ok, "123"} = Transport.encode_and_post_envelope(envelope, FinchClient)
3837
end
3938

4039
test "returns an error if the HTTP client returns a badly-typed response" do
@@ -70,10 +69,12 @@ defmodule Sentry.TransportTest do
7069

7170
Bypass.down(bypass)
7271

73-
assert {:request_failure, :econnrefused} =
74-
error(fn ->
75-
Transport.encode_and_post_envelope(envelope, HackneyClient, _retries = [])
76-
end)
72+
assert {:error,
73+
%Sentry.ClientError{
74+
reason: {:request_failure, %Mint.TransportError{reason: :econnrefused}},
75+
http_response: nil
76+
}} =
77+
Transport.encode_and_post_envelope(envelope, FinchClient, _retries = [])
7778
end
7879

7980
test "returns an error if the response from Sentry is not 200", %{bypass: bypass} do
@@ -86,7 +87,7 @@ defmodule Sentry.TransportTest do
8687
end)
8788

8889
{:error, %ClientError{} = error} =
89-
Transport.encode_and_post_envelope(envelope, HackneyClient, _retries = [])
90+
Transport.encode_and_post_envelope(envelope, FinchClient, _retries = [])
9091

9192
assert error.reason == :server_error
9293
assert {400, headers, "{}"} = error.http_response
@@ -172,7 +173,7 @@ defmodule Sentry.TransportTest do
172173

173174
assert {:error, %RuntimeError{message: "I'm a really bad JSON library"}, _stacktrace} =
174175
error(fn ->
175-
Transport.encode_and_post_envelope(envelope, HackneyClient, _retries = [])
176+
Transport.encode_and_post_envelope(envelope, FinchClient, _retries = [])
176177
end)
177178
after
178179
:code.delete(CrashingJSONLibrary)
@@ -192,7 +193,7 @@ defmodule Sentry.TransportTest do
192193

193194
assert {:request_failure, error} =
194195
error(fn ->
195-
Transport.encode_and_post_envelope(envelope, HackneyClient, _retries = [0])
196+
Transport.encode_and_post_envelope(envelope, FinchClient, _retries = [0])
196197
end)
197198

198199
if Version.match?(System.version(), "~> 1.18") do
@@ -225,7 +226,7 @@ defmodule Sentry.TransportTest do
225226
end)
226227

227228
assert {:ok, "123"} =
228-
Transport.encode_and_post_envelope(envelope, HackneyClient, _retries = [10, 25])
229+
Transport.encode_and_post_envelope(envelope, FinchClient, _retries = [10, 25])
229230

230231
assert System.system_time(:millisecond) - start_time >= 35
231232

@@ -249,12 +250,12 @@ defmodule Sentry.TransportTest do
249250

250251
assert :too_many_retries =
251252
error(fn ->
252-
Transport.encode_and_post_envelope(envelope, HackneyClient, _retries = [])
253+
Transport.encode_and_post_envelope(envelope, FinchClient, _retries = [])
253254
end)
254255

255256
log =
256257
capture_log(fn ->
257-
Transport.encode_and_post_envelope(envelope, HackneyClient, _retries = [])
258+
Transport.encode_and_post_envelope(envelope, FinchClient, _retries = [])
258259
end)
259260

260261
assert log =~ "[warning]"

0 commit comments

Comments
 (0)