Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky specs #2561

Merged
merged 7 commits into from
Feb 17, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Stub requests in event sending spec
This spec was very flaky
solnic committed Feb 17, 2025
commit c9b6bd3e598e90dbaefd64fcf16ff1b5f6a0aca9
25 changes: 21 additions & 4 deletions sentry-ruby/spec/sentry/client/event_sending_spec.rb
Original file line number Diff line number Diff line change
@@ -10,6 +10,11 @@
config.transport.transport_class = Sentry::DummyTransport
end
end

before do
stub_request(:post, Sentry::TestHelper::DUMMY_DSN)
end

subject(:client) { Sentry::Client.new(configuration) }

let(:hub) do
@@ -470,13 +475,16 @@
before do
configuration.background_worker_threads = 0
Sentry.background_worker = Sentry::BackgroundWorker.new(configuration)

stub_request(:post, "http://sentry.localdomain/sentry/api/42/envelope/")
.to_raise(Timeout::Error)
end

it "swallows and logs Sentry::ExternalError (caused by transport's networking error)" do
expect(client.capture_event(event, scope)).to be_nil

expect(string_io.string).to match(/Event sending failed: Failed to open TCP connection/)
expect(string_io.string).to match(/Event capturing failed: Failed to open TCP connection/)
expect(string_io.string).to match(/Event sending failed: Exception from WebMock/)
expect(string_io.string).to match(/Event capturing failed: Exception from WebMock/)
end

it "swallows and logs errors caused by the user (like in before_send)" do
@@ -502,13 +510,16 @@
context "when sending events in background causes error", retry: 3 do
before do
Sentry.background_worker = Sentry::BackgroundWorker.new(configuration)

stub_request(:post, "http://sentry.localdomain/sentry/api/42/envelope/")
.to_raise(Timeout::Error)
end

it "swallows and logs Sentry::ExternalError (caused by transport's networking error)" do
expect(client.capture_event(event, scope)).to be_a(Sentry::ErrorEvent)
sleep(0.2)

expect(string_io.string).to match(/Event sending failed: Failed to open TCP connection/)
expect(string_io.string).to match(/Event sending failed: Exception from WebMock/)
end

it "swallows and logs errors caused by the user (like in before_send)" do
@@ -560,11 +571,14 @@
describe "#send_event" do
context "error happens when sending the event" do
it "raises the error" do
stub_request(:post, "http://sentry.localdomain/sentry/api/42/envelope/")
.to_raise(Timeout::Error)

expect do
client.send_event(event)
end.to raise_error(Sentry::ExternalError)

expect(string_io.string).to match(/Event sending failed: Failed to open TCP connection/)
expect(string_io.string).to match(/Event sending failed: Exception from WebMock/)
end
end

@@ -635,6 +649,9 @@
end

it "records lost span delta client reports" do
stub_request(:post, "http://sentry.localdomain/sentry/api/42/envelope/")
.to_raise(Timeout::Error)

expect { client.send_event(transaction_event) }.to raise_error(Sentry::ExternalError)
expect(client.transport).to have_recorded_lost_event(:before_send, 'span', num: 2)
end