mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-13 07:49:29 +00:00
Use thread support helper in concurrent insert tag spec (#37112)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user