Skip to content

Fix Sidekiq mailer specs

Sean McGivern requested to merge fix-sidekiq-mailer-specs into master

These specs were using a code snippet copied from a GitHub issue comment, but I missed our resetting the test adapter correctly. Also move this to spec metadata so we can easily reuse it elsewhere if we need to.

The reason we need this anyway is because we can't easily set a non-test adapter for ActiveJob in tests: either for a specific test, or globally. (Request specs will get set back to the test adapter.) See !62902 (closed) where I tried setting this to use Sidekiq globally.

To test this locally, just run these two specs one after the other: bundle exec rspec spec/lib/marginalia_spec.rb spec/initializers/mailer_retries_spec.rb. Before:

...F

Failures:

  1) Mailer retries sets retries for mailers to 3
     Failure/Error: expect(Sidekiq::Queues['mailers'].first).to include('retry' => 3)
       expected nil to include {"retry" => 3}, but it does not respond to `include?`
     # ./spec/initializers/mailer_retries_spec.rb:23:in `block (2 levels) in <main>'
     # ./spec/initializers/mailer_retries_spec.rb:15:in `block (2 levels) in <main>'
     # ./spec/spec_helper.rb:372:in `block (3 levels) in <main>'
     # ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
     # ./spec/spec_helper.rb:363:in `block (2 levels) in <main>'
     # ./spec/spec_helper.rb:359:in `block (3 levels) in <main>'
     # ./lib/gitlab/application_context.rb:31:in `with_raw_context'
     # ./spec/spec_helper.rb:359:in `block (2 levels) in <main>'
     # -e:1:in `<main>'

Finished in 11.62 seconds (files took 2.36 seconds to load)
4 examples, 1 failure

Failed examples:

rspec ./spec/initializers/mailer_retries_spec.rb:20 # Mailer retries sets retries for mailers to 3

After:

....

Finished in 24 minutes 20 seconds (files took 2.75 seconds to load)
4 examples, 0 failures

For #332645 (closed).

Edited by Sean McGivern

Merge request reports

Loading