Skip to content

Commit e3d816d

Browse files
committed
Merge pull request #196 from ruby-concurrency/thread-local-var
Count with GC may fail to run
2 parents 08f6c4f + 6a98fe9 commit e3d816d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

spec/concurrent/atomic/thread_local_var_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,24 @@ module Concurrent
4444
context 'GC' do
4545
it 'does not leave values behind when bind is used' do
4646
var = ThreadLocalVar.new(0)
47-
100.times.map do |i|
47+
10.times.map do |i|
4848
Thread.new { var.bind(i) { var.value } }
4949
end.each(&:join)
5050
var.value = 0
5151
expect(var.instance_variable_get(:@storage).keys.size).to be == 1
5252
end
5353

5454
it 'does not leave values behind when bind is not used' do
55-
var = ThreadLocalVar.new(0)
56-
100.times.map do |i|
57-
Thread.new { var.value = i; var.value }
58-
end.each(&:join)
59-
var.value = 0
60-
sleep 0.1
61-
GC.start
62-
sleep 0.1
63-
GC.start
64-
expect(var.instance_variable_get(:@storage).keys.size).to be == 1
55+
tries = Array.new(10) do
56+
var = ThreadLocalVar.new(0)
57+
10.times.map do |i|
58+
Thread.new { var.value = i; var.value }
59+
end.each(&:join)
60+
var.value = 0
61+
GC.start
62+
var.instance_variable_get(:@storage).keys.size == 1
63+
end
64+
expect(tries.any?).to be_truthy
6565
end
6666
end
6767
end

0 commit comments

Comments
 (0)