Skip to content

Commit

Permalink
Fix failing tests (#22687)
Browse files Browse the repository at this point in the history
* Adding skips for tests

* Trigger Build

* Unskip tests for troubleshooting

* Have SqsService spec use its own queue

* Add back in DB persistence across threads in SyncDecidedAppealsHelper spec

* Set current_user in each parallel thread

* Wrap threads in executors

---------

Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>
  • Loading branch information
2 people authored and AdamShawBAH committed Sep 9, 2024
1 parent 3b09890 commit 6e5ce4b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
14 changes: 7 additions & 7 deletions app/helpers/sync_decided_appeals_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ def sync_decided_appeals
.pluck(:id, :vacols_id)

appeal_state_ids_hash = appeal_state_ids.to_h

vacols_decision_dates = get_decision_dates(appeal_state_ids_hash.values).to_h

ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
Parallel.each(appeal_state_ids_hash, in_threads: 4) do |appeal_state_hash|
appeal_state_id = appeal_state_hash[0]
vacols_id = appeal_state_hash[1]
# If there is a decision date on the VACOLS record,
# update the decision_mailed status on the AppealState to true
if vacols_decision_dates[vacols_id].present?
AppealState.find(appeal_state_id).decision_mailed_appeal_state_update_action!
Rails.application.executor.wrap do
appeal_state_id, vacols_id = appeal_state_hash
# If there is a decision date on the VACOLS record,
# update the decision_mailed status on the AppealState to true
if vacols_decision_dates[vacols_id].present?
AppealState.find(appeal_state_id).decision_mailed_appeal_state_update_action!
end
end
end
end
Expand Down
17 changes: 9 additions & 8 deletions spec/services/sqs_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

describe SqsService do
let(:sqs_client) { SqsService.sqs_client }
let(:test_queue_prefix) { "sqs_service_test_" }

before(:each) { wipe_queues }
after(:all) { wipe_queues }
Expand All @@ -13,15 +14,15 @@

context "FIFO" do
let(:fifo) { true }
let(:queue_name) { "my_fifo_queue" }
let(:queue_name) { "#{test_queue_prefix}my_fifo_queue" }

it "the queue is found and is validated to be a FIFO queue" do
expect(subject { SqsService.find_queue_url_by_name(name: queue_name, check_fifo: true) })
.to include("caseflow_test_my_fifo_queue.fifo")
.to include("sqs_service_test_my_fifo_queue.fifo")
end

it "the queue is found while validation is opted out" do
is_expected.to include("caseflow_test_my_fifo_queue.fifo")
is_expected.to include("sqs_service_test_my_fifo_queue.fifo")
end

it "a non-existent queue cannot be found" do
Expand All @@ -34,17 +35,17 @@

context "non-FIFO" do
let(:fifo) { false }
let(:queue_name) { "my_normal_queue" }
let(:queue_name) { "#{test_queue_prefix}my_normal_queue" }

it "the queue is found" do
is_expected.to include("caseflow_test_my_normal_queue")
is_expected.to include("sqs_service_test_my_normal_queue")
is_expected.to_not include(".fifo")
end

it "the queue found fails the FIFO check" do
expect { SqsService.find_queue_url_by_name(name: queue_name, check_fifo: true) }.to raise_error do |error|
expect(error).to be_a(Caseflow::Error::SqsUnexpectedQueueTypeError)
expect(error.to_s).to include("No FIFO queue with name my_normal_queue could be located.")
expect(error.to_s).to include("No FIFO queue with name #{test_queue_prefix}my_normal_queue could be located.")
end
end
end
Expand Down Expand Up @@ -97,7 +98,7 @@

def create_queue(name, fifo = false)
sqs_client.create_queue({
queue_name: "caseflow_test_#{name}#{fifo ? '.fifo' : ''}".to_sym,
queue_name: "#{name}#{fifo ? '.fifo' : ''}".to_sym,
attributes: fifo ? { "FifoQueue" => "true" } : {}
})
end
Expand Down Expand Up @@ -127,7 +128,7 @@ def approximate_number_of_messages_in_queue(queue_url)
def wipe_queues
client = SqsService.sqs_client

queues_to_delete = client.list_queues.queue_urls.filter { _1.include?("caseflow_test") }
queues_to_delete = client.list_queues.queue_urls.filter { _1.include?("sqs_service_spec") }

queues_to_delete.each do |queue_url|
client.delete_queue(queue_url: queue_url)
Expand Down

0 comments on commit 6e5ce4b

Please sign in to comment.