mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-18 10:37:45 +00:00
Use thread support helper in concurrent insert tag spec (#37112)
This commit is contained in:
@@ -287,15 +287,9 @@ RSpec.describe Tag do
|
|||||||
tag_name_upper = 'Rails'
|
tag_name_upper = 'Rails'
|
||||||
tag_name_lower = 'rails'
|
tag_name_lower = 'rails'
|
||||||
|
|
||||||
threads = []
|
multi_threaded_execution(2) do |index|
|
||||||
|
described_class.find_or_create_by_names(index.zero? ? tag_name_upper : tag_name_lower)
|
||||||
2.times do |i|
|
|
||||||
threads << Thread.new do
|
|
||||||
described_class.find_or_create_by_names(i.zero? ? tag_name_upper : tag_name_lower)
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
threads.each(&:join)
|
|
||||||
|
|
||||||
tags = described_class.where('lower(name) = ?', tag_name_lower.downcase)
|
tags = described_class.where('lower(name) = ?', tag_name_lower.downcase)
|
||||||
expect(tags.count).to eq(1)
|
expect(tags.count).to eq(1)
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ module ThreadingHelpers
|
|||||||
def multi_threaded_execution(thread_count)
|
def multi_threaded_execution(thread_count)
|
||||||
barrier = Concurrent::CyclicBarrier.new(thread_count)
|
barrier = Concurrent::CyclicBarrier.new(thread_count)
|
||||||
|
|
||||||
threads = Array.new(thread_count) do
|
threads = Array.new(thread_count) do |index|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
barrier.wait
|
barrier.wait
|
||||||
yield
|
yield(index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user