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

fixed linting on sync and added test for RedisMutex lock error #19237

Merged
merged 10 commits into from
Aug 25, 2023
3 changes: 2 additions & 1 deletion app/models/end_product_establishment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ def sync!
save_updated_end_product_code!
end
rescue RedisMutex::LockError
Rails.logger.error("failed to acquire lock! EPE sync is being called by another process. Please try again later.")
Rails.logger.error("Failed to acquire lock for EPE ID: #{id}! #sync! is being"\
" called by another process. Please try again later.")
rescue EstablishedEndProductNotFound, AppealRepository::AppealNotValidToReopen => error
raise error
rescue StandardError => error
Expand Down
13 changes: 13 additions & 0 deletions spec/models/end_product_establishment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,19 @@
]
end

context "when lock acquisition fails" do
before do
allow(RedisMutex).to receive(:with_lock).and_raise(RedisMutex::LockError)
end

it "logs the error message" do
expect(Rails.logger).to receive(:error)
.with("Failed to acquire lock for EPE ID: #{end_product_establishment.id}!"\
" #sync! is being called by another process. Please try again later.")
end_product_establishment.sync!
end
end

context "when matching end product has not yet been established" do
it "raises EstablishedEndProductNotFound error" do
expect { subject }.to raise_error(EndProductEstablishment::EstablishedEndProductNotFound)
Expand Down
Loading