From dcedffac2fe2ed24eb433600f741984161e55904 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 21 Mar 2025 15:11:46 +1100 Subject: [PATCH] Ensure we wait for all threads in spec --- spec/jobs/open_order_cycle_job_spec.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/jobs/open_order_cycle_job_spec.rb b/spec/jobs/open_order_cycle_job_spec.rb index 0a25161360..383d24f4d1 100644 --- a/spec/jobs/open_order_cycle_job_spec.rb +++ b/spec/jobs/open_order_cycle_job_spec.rb @@ -90,12 +90,16 @@ RSpec.describe OpenOrderCycleJob do # Resume and complete both jobs: breakpoint.unlock - # Join each thread to the main thread to ensure they end. - # Any exceptions that were raised, are raised to the main thread. - # We're expecting RecordNotFound because the record was locked by the first concurrent thread. - expect{ - threads.each(&:join) + # Join the threads until an error is raised. + # We expect one of them to raise an error but we don't know which one. + expect { + threads.pop.join + threads.pop.join }.to raise_error ActiveRecord::RecordNotFound + + # If the first `join` raised an error, we still need to wait for the + # second thread to finish: + threads.pop.join if threads.present? end end end