Skip to content

Commit

Permalink
fixed linting on sync and added test for RedisMutex lock error (#19237)
Browse files Browse the repository at this point in the history
* fixed linting on sync and added test for RedisMutex lock error

* added epe id to display in error message

* fixed linting

* rubocop long line fixes

* fixed new line causing test failure

* fixed new lines

* fixed rubocop long lines

* APPEALS-28960 Updated formatting of log message and content to include "#sync!".

---------

Co-authored-by: TuckerRose <tuckerrose@tuckerroses-mbp.lan>
Co-authored-by: Jeffrey Aaron Willis <Willis_Jeffrey@bah.com>
  • Loading branch information
3 people committed Aug 28, 2023
1 parent dd3d865 commit 933411b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/end_product_establishment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,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

0 comments on commit 933411b

Please sign in to comment.