Use thread support helper in concurrent insert tag spec (#37112)

This commit is contained in:
Matt Jankowski
2025-12-04 04:11:53 -05:00
committed by GitHub
parent d063af2594
commit 832d8c7397
2 changed files with 4 additions and 10 deletions

View File

@@ -287,16 +287,10 @@ RSpec.describe Tag do
tag_name_upper = 'Rails'
tag_name_lower = 'rails'
threads = []
2.times do |i|
threads << Thread.new do
described_class.find_or_create_by_names(i.zero? ? tag_name_upper : tag_name_lower)
end
multi_threaded_execution(2) do |index|
described_class.find_or_create_by_names(index.zero? ? tag_name_upper : tag_name_lower)
end
threads.each(&:join)
tags = described_class.where('lower(name) = ?', tag_name_lower.downcase)
expect(tags.count).to eq(1)
expect(tags.first.name.downcase).to eq(tag_name_lower.downcase)

View File

@@ -6,10 +6,10 @@ module ThreadingHelpers
def multi_threaded_execution(thread_count)
barrier = Concurrent::CyclicBarrier.new(thread_count)
threads = Array.new(thread_count) do
threads = Array.new(thread_count) do |index|
Thread.new do
barrier.wait
yield
yield(index)
end
end