Consolidate configuration of `Sidekiq::Testing.fake!` setup (#28046)

th-new
Matt Jankowski 2023-11-23 04:43:43 -05:00 committed by GitHub
parent c810b197ad
commit 973597c6f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 28 additions and 65 deletions

View File

@ -9,13 +9,7 @@ describe Api::V1::Statuses::ReblogsController do
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:statuses', application: app) }
context 'with an oauth token' do
around do |example|
Sidekiq::Testing.fake! do
example.run
end
end
context 'with an oauth token', :sidekiq_fake do
before do
allow(controller).to receive(:doorkeeper_token) { token }
end

View File

@ -38,12 +38,10 @@ describe Settings::ExportsController do
expect(response).to redirect_to(settings_export_path)
end
it 'queues BackupWorker job by 1' do
Sidekiq::Testing.fake! do
expect do
post :create
end.to change(BackupWorker.jobs, :size).by(1)
end
it 'queues BackupWorker job by 1', :sidekiq_fake do
expect do
post :create
end.to change(BackupWorker.jobs, :size).by(1)
end
end
end

View File

@ -23,7 +23,7 @@ RSpec.describe ActivityPub::Activity::Create do
stub_request(:get, 'http://example.com/emojib.png').to_return(body: attachment_fixture('emojo.png'), headers: { 'Content-Type' => 'application/octet-stream' })
end
describe 'processing posts received out of order' do
describe 'processing posts received out of order', :sidekiq_fake do
let(:follower) { Fabricate(:account, username: 'bob') }
let(:object_json) do
@ -77,13 +77,6 @@ RSpec.describe ActivityPub::Activity::Create do
follower.follow!(sender)
end
around do |example|
Sidekiq::Testing.fake! do
example.run
Sidekiq::Worker.clear_all
end
end
it 'correctly processes posts and inserts them in timelines', :aggregate_failures do
# Simulate a temporary failure preventing from fetching the parent post
stub_request(:get, object_json[:id]).to_return(status: 500)

View File

@ -46,12 +46,10 @@ RSpec.describe Admin::AccountAction do
expect(target_account).to be_suspended
end
it 'queues Admin::SuspensionWorker by 1' do
Sidekiq::Testing.fake! do
expect do
subject
end.to change { Admin::SuspensionWorker.jobs.size }.by 1
end
it 'queues Admin::SuspensionWorker by 1', :sidekiq_fake do
expect do
subject
end.to change { Admin::SuspensionWorker.jobs.size }.by 1
end
end

View File

@ -95,6 +95,13 @@ RSpec.configure do |config|
self.use_transactional_tests = true
end
config.around(:each, :sidekiq_fake) do |example|
Sidekiq::Testing.fake! do
example.run
Sidekiq::Worker.clear_all
end
end
config.before :each, type: :cli do
stub_stdout
stub_reset_connection_pools

View File

@ -70,19 +70,13 @@ RSpec.describe 'Favourites' do
end
end
describe 'POST /api/v1/statuses/:status_id/unfavourite' do
describe 'POST /api/v1/statuses/:status_id/unfavourite', :sidekiq_fake do
subject do
post "/api/v1/statuses/#{status.id}/unfavourite", headers: headers
end
let(:status) { Fabricate(:status) }
around do |example|
Sidekiq::Testing.fake! do
example.run
end
end
it_behaves_like 'forbidden for wrong scope', 'read read:favourites'
context 'with public status' do

View File

@ -12,14 +12,7 @@ RSpec.describe BulkImportService do
import.update(total_items: import.rows.count)
end
describe '#call' do
around do |example|
Sidekiq::Testing.fake! do
example.run
Sidekiq::Worker.clear_all
end
end
describe '#call', :sidekiq_fake do
context 'when importing follows' do
let(:import_type) { 'following' }
let(:overwrite) { false }

View File

@ -111,7 +111,7 @@ RSpec.describe UpdateStatusService, type: :service do
end
end
context 'when poll changes' do
context 'when poll changes', :sidekiq_fake do
let(:account) { Fabricate(:account) }
let!(:status) { Fabricate(:status, text: 'Foo', account: account, poll_attributes: { options: %w(Foo Bar), account: account, multiple: false, hide_totals: false, expires_at: 7.days.from_now }) }
let!(:poll) { status.poll }
@ -120,9 +120,7 @@ RSpec.describe UpdateStatusService, type: :service do
before do
status.update(poll: poll)
VoteService.new.call(voter, poll, [0])
Sidekiq::Testing.fake! do
subject.call(status, status.account_id, text: 'Foo', poll: { options: %w(Bar Baz Foo), expires_in: 5.days.to_i })
end
subject.call(status, status.account_id, text: 'Foo', poll: { options: %w(Bar Baz Foo), expires_in: 5.days.to_i })
end
it 'updates poll' do

View File

@ -159,12 +159,9 @@ describe MoveWorker do
describe '#perform' do
context 'when both accounts are distant' do
it 'calls UnfollowFollowWorker' do
Sidekiq::Testing.fake! do
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, false)
Sidekiq::Worker.drain_all
end
it 'calls UnfollowFollowWorker', :sidekiq_fake do
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, false)
end
include_examples 'common tests'
@ -173,12 +170,9 @@ describe MoveWorker do
context 'when target account is local' do
let(:target_account) { Fabricate(:account) }
it 'calls UnfollowFollowWorker' do
Sidekiq::Testing.fake! do
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, true)
Sidekiq::Worker.clear_all
end
it 'calls UnfollowFollowWorker', :sidekiq_fake do
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, true)
end
include_examples 'common tests'

View File

@ -10,13 +10,7 @@ describe PollExpirationNotifyWorker do
let(:remote?) { false }
let(:poll_vote) { Fabricate(:poll_vote, poll: poll) }
describe '#perform' do
around do |example|
Sidekiq::Testing.fake! do
example.run
end
end
describe '#perform', :sidekiq_fake do
it 'runs without error for missing record' do
expect { worker.perform(nil) }.to_not raise_error
end