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

Fix flaky specs #2561

merged 7 commits into from
Feb 17, 2025

Conversation

solnic
Copy link
Collaborator

@solnic solnic commented Feb 14, 2025

Our spec suite has become very unstable. I've managed to track it down to issues related to specs that set up HTTPTransport and then having request stubbing not really working. This PR adds Webmock that guarantees that we don't send HTTP requests unintentionally and keeps using our customized Net::HTTP stubbing context untouched and used the same way in specs where it is needed.

One especially problematic crash was a transport failure after spec suite run. I tracked it down to one specific spec - it lacked some configuration so I moved it to the context where that configuration is present, and the error went away, see 0c1476b.

It fixes most of the problems with flakiness, issue #2522 still lists some random failures that should be addressed so I'm keeping it open.

I think it's worth merging this in already.

Refs #2522

#skip-changelog

@solnic solnic linked an issue Feb 14, 2025 that may be closed by this pull request
@solnic solnic changed the title Solnic/2522 fix flaky specs Fix flaky specs Feb 14, 2025
Copy link

codecov bot commented Feb 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.11%. Comparing base (ef2ea49) to head (a744a55).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2561   +/-   ##
=======================================
  Coverage   64.11%   64.11%           
=======================================
  Files         123      123           
  Lines        4724     4724           
=======================================
  Hits         3029     3029           
  Misses       1695     1695           
Components Coverage Δ
sentry-ruby 59.84% <ø> (ø)
sentry-rails 59.22% <ø> (ø)
sentry-sidekiq 97.16% <ø> (ø)
sentry-resque 92.85% <ø> (ø)
sentry-delayed_job 95.65% <ø> (ø)
sentry-opentelemetry 99.31% <ø> (ø)
Files with missing lines Coverage Δ
sentry-ruby/lib/sentry/transport/http_transport.rb 25.00% <ø> (ø)

@solnic solnic force-pushed the solnic/2522-fix-flaky-specs branch 3 times, most recently from 65bafad to 8c292a3 Compare February 17, 2025 13:34
Not sure what the intention was but this spec
did not test any faraday error handling. What
actually happened was that HTTPTransport really
tried to hit the API and ended up with error.

We *do not* want to hit any APIs like that in specs,
this causes instability of the spec suite.

That's why I added webmock to ensure we're not sending
any HTTP requests in specs.
This spec was very flaky
@solnic solnic force-pushed the solnic/2522-fix-flaky-specs branch from 8c292a3 to 0c1476b Compare February 17, 2025 13:51
@solnic solnic marked this pull request as ready for review February 17, 2025 13:56
before do
stub_request(:post, "http://sentry.localdomain:80/sentry/api/42/envelope/").
to_raise(Timeout::Error)
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know what the intention of this spec was originally since Faraday was NOT configured here and the spec was passing by an accident since there was a socket timeout raised under the hood.

I can add a faraday spec too. Just lemme know if it'd make sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a leftover from the legacy Raven SDK, ignore

rescue Faraday::Error => e

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we may just remove the entire test case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna leave it. It does verify specific error handling - HTTPTransport defines a list of exceptions that are rescued in send_data and now this spec checks that it works as expected that the exception is wrapped in Sentry::ExternalError.

Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merci!

@solnic solnic force-pushed the solnic/2522-fix-flaky-specs branch from 0c1476b to a744a55 Compare February 17, 2025 14:07
@solnic solnic merged commit db975df into master Feb 17, 2025
150 of 151 checks passed
@solnic solnic deleted the solnic/2522-fix-flaky-specs branch February 17, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix flaky specs
3 participants