Skip to content

Commit a515290

Browse files
flavorjonespitr-ch
authored andcommitted
test: add coverage for thread-safety of Concurrent::Set#each
Related to #900
1 parent 382550c commit a515290

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

spec/concurrent/set_spec.rb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module Concurrent
4242
end
4343

4444
context 'concurrency' do
45-
it do
45+
it '#add and #delete' do
4646
(1..Concurrent::ThreadSafe::Test::THREADS).map do |i|
4747
in_thread do
4848
1000.times do
@@ -55,6 +55,36 @@ module Concurrent
5555
end.map(&:join)
5656
expect(set).to be_empty
5757
end
58+
59+
it '#each' do
60+
threads = []
61+
("a".."z").inject(set, &:<<) # setup a non-empty set
62+
63+
threads << in_thread do
64+
2000.times do
65+
size = nil
66+
set.each do |member|
67+
if size.nil?
68+
size = set.length
69+
else
70+
expect(set.length).to eq(size)
71+
end
72+
end
73+
end
74+
end
75+
76+
threads += (1..19).map do |i|
77+
in_thread do
78+
v = i * 1000
79+
10.times do
80+
200.times { |j| set << (v+j) }
81+
200.times { |j| set.delete(v+j) }
82+
end
83+
end
84+
end
85+
86+
threads.map(&:join)
87+
end
5888
end
5989
end
6090
end

0 commit comments

Comments
 (0)