Skip to content

Commit

Permalink
test: add coverage for thread-safety of Concurrent::Set#each
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Apr 20, 2021
1 parent 7b7900a commit 873ca0c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion spec/concurrent/set_spec.rb
Expand Up @@ -42,7 +42,7 @@ module Concurrent
end

context 'concurrency' do
it do
it '#add and #delete' do
(1..Concurrent::ThreadSafe::Test::THREADS).map do |i|
in_thread do
1000.times do
Expand All @@ -55,6 +55,36 @@ module Concurrent
end.map(&:join)
expect(set).to be_empty
end

it '#each' do
threads = []
("a".."z").inject(set, &:<<) # setup a non-empty set

threads << in_thread do
2000.times do
size = nil
set.each do |member|
if size.nil?
size = set.length
else
expect(set.length).to eq(size)
end
end
end
end

threads += (1..19).map do |i|
in_thread do
v = i * 1000
10.times do
200.times { |j| set << (v+j) }
200.times { |j| set.delete(v+j) }
end
end
end

threads.map(&:join)
end
end
end
end

0 comments on commit 873ca0c

Please sign in to comment.