Skip to content

Commit 4b70f6e

Browse files
committed
Merge pull request #228 from ruby-concurrency/thread-local-var
Add sleep to stabilize ThreadLocalVariable test
2 parents 1241953 + 9a15c07 commit 4b70f6e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

spec/concurrent/atomic/thread_local_var_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ module Concurrent
5050
var.value = 0
5151
expect(var.instance_variable_get(:@storage).keys.size).to be == 1
5252
end
53+
54+
it 'does not leave values behind when bind is not used' do
55+
skip 'GC.run works reliably only on MRI' unless mri? # TODO
56+
57+
result = 7.times.any? do |i|
58+
var = ThreadLocalVar.new(0)
59+
5.times.map { |i| Thread.new { var.value = i; var.value } }.each(&:join)
60+
var.value = 0
61+
# TODO find out why long sleep is necessary, does it take longer for threads to be collected?
62+
sleep 0.1 * 2**i
63+
GC.start
64+
65+
var.instance_variable_get(:@storage).keys.size == 1
66+
end
67+
68+
expect(result).to be_truthy
69+
end
5370
end
5471
end
5572

0 commit comments

Comments
 (0)