mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-01-19 03:36:05 +01:00
Test all cases of error handling for ShareWorker
This commit is contained in:
parent
45dae78ed0
commit
a534dd04d5
1 changed files with 16 additions and 1 deletions
|
@ -32,15 +32,30 @@ describe ShareWorker do
|
||||||
context 'when answer doesn\'t exist' do
|
context 'when answer doesn\'t exist' do
|
||||||
it 'prevents the job from retrying and logs a message' do
|
it 'prevents the job from retrying and logs a message' do
|
||||||
answer.destroy!
|
answer.destroy!
|
||||||
Sidekiq.logger.should_receive(:info)
|
Sidekiq.logger.should_receive(:info).with("Tried to post answer ##{answer.id} for user ##{user.id} to Twitter but the user/answer/service did not exist (likely deleted), will not retry.")
|
||||||
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
||||||
expect { ShareWorker.drain }.to change(ShareWorker.jobs, :size).by(-1)
|
expect { ShareWorker.drain }.to change(ShareWorker.jobs, :size).by(-1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when answer exists' do
|
context 'when answer exists' do
|
||||||
|
it 'handles Twitter::Error::DuplicateStatus' do
|
||||||
|
allow_any_instance_of(Services::Twitter).to receive(:post).with(answer).and_raise(Twitter::Error::DuplicateStatus)
|
||||||
|
Sidekiq.logger.should_receive(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the status was already posted.")
|
||||||
|
subject
|
||||||
|
ShareWorker.drain
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'handles Twitter::Error::Unauthorized' do
|
||||||
|
allow_any_instance_of(Services::Twitter).to receive(:post).with(answer).and_raise(Twitter::Error::Unauthorized)
|
||||||
|
Sidekiq.logger.should_receive(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the token has exired or been revoked.")
|
||||||
|
subject
|
||||||
|
ShareWorker.drain
|
||||||
|
end
|
||||||
|
|
||||||
it 'retries on unhandled exceptions' do
|
it 'retries on unhandled exceptions' do
|
||||||
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
||||||
|
Sidekiq.logger.should_receive(:info)
|
||||||
expect { ShareWorker.drain }.to raise_error(Twitter::Error::BadRequest)
|
expect { ShareWorker.drain }.to raise_error(Twitter::Error::BadRequest)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue