Skip to content

Commit 8dfeed0

Browse files
committed
Disabled TLV tests on Ruby 1.9.3
1 parent 15e3efe commit 8dfeed0

File tree

1 file changed

+81
-78
lines changed

1 file changed

+81
-78
lines changed

spec/concurrent/atomic/thread_local_var_spec.rb

Lines changed: 81 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,108 @@
1-
require 'rbconfig'
1+
unless Concurrent.ruby_version(:<, 2)
22

3-
module Concurrent
3+
require 'rbconfig'
44

5-
require 'concurrent/atomic/thread_local_var'
5+
module Concurrent
66

7-
describe ThreadLocalVar do
7+
require 'concurrent/atomic/thread_local_var'
88

9-
subject { ThreadLocalVar.new }
9+
describe ThreadLocalVar do
1010

11-
context '#initialize' do
11+
subject { ThreadLocalVar.new }
1212

13-
it 'can set an initial value' do
14-
v = ThreadLocalVar.new(14)
15-
expect(v.value).to eq 14
16-
end
17-
18-
it 'sets nil as a default initial value' do
19-
v = ThreadLocalVar.new
20-
expect(v.value).to be_nil
21-
end
13+
context '#initialize' do
2214

23-
it 'sets the same initial value for all threads' do
24-
v = ThreadLocalVar.new(14)
25-
t1 = Thread.new { v.value }
26-
t2 = Thread.new { v.value }
27-
expect(t1.value).to eq 14
28-
expect(t2.value).to eq 14
29-
end
30-
31-
if Concurrent.on_jruby?
32-
it 'extends JavaThreadLocalVar' do
33-
expect(subject.class.ancestors).to include(Concurrent::JavaThreadLocalVar)
34-
end
35-
else
36-
it 'extends RubyThreadLocalVar' do
37-
expect(subject.class.ancestors).to include(Concurrent::RubyThreadLocalVar)
15+
it 'can set an initial value' do
16+
v = ThreadLocalVar.new(14)
17+
expect(v.value).to eq 14
3818
end
39-
end
40-
end
4119

42-
context '#value' do
20+
it 'sets nil as a default initial value' do
21+
v = ThreadLocalVar.new
22+
expect(v.value).to be_nil
23+
end
4324

44-
it 'returns the current value' do
45-
v = ThreadLocalVar.new(14)
46-
expect(v.value).to eq 14
47-
end
25+
it 'sets the same initial value for all threads' do
26+
v = ThreadLocalVar.new(14)
27+
t1 = Thread.new { v.value }
28+
t2 = Thread.new { v.value }
29+
expect(t1.value).to eq 14
30+
expect(t2.value).to eq 14
31+
end
4832

49-
it 'returns the value after modification' do
50-
v = ThreadLocalVar.new(14)
51-
v.value = 2
52-
expect(v.value).to eq 2
33+
if Concurrent.on_jruby?
34+
it 'extends JavaThreadLocalVar' do
35+
expect(subject.class.ancestors).to include(Concurrent::JavaThreadLocalVar)
36+
end
37+
else
38+
it 'extends RubyThreadLocalVar' do
39+
expect(subject.class.ancestors).to include(Concurrent::RubyThreadLocalVar)
40+
end
41+
end
5342
end
54-
end
55-
56-
context '#value=' do
5743

58-
it 'sets a new value' do
59-
v = ThreadLocalVar.new(14)
60-
v.value = 2
61-
expect(v.value).to eq 2
62-
end
44+
context '#value' do
6345

64-
it 'returns the new value' do
65-
v = ThreadLocalVar.new(14)
66-
expect(v.value = 2).to eq 2
67-
end
46+
it 'returns the current value' do
47+
v = ThreadLocalVar.new(14)
48+
expect(v.value).to eq 14
49+
end
6850

69-
it 'does not modify the initial value for other threads' do
70-
v = ThreadLocalVar.new(14)
71-
v.value = 2
72-
t = Thread.new { v.value }
73-
expect(t.value).to eq 14
51+
it 'returns the value after modification' do
52+
v = ThreadLocalVar.new(14)
53+
v.value = 2
54+
expect(v.value).to eq 2
55+
end
7456
end
7557

76-
it 'does not modify the value for other threads' do
77-
v = ThreadLocalVar.new(14)
78-
v.value = 2
58+
context '#value=' do
7959

80-
b1 = CountDownLatch.new(2)
81-
b2 = CountDownLatch.new(2)
60+
it 'sets a new value' do
61+
v = ThreadLocalVar.new(14)
62+
v.value = 2
63+
expect(v.value).to eq 2
64+
end
8265

83-
t1 = Thread.new do
84-
b1.count_down
85-
b1.wait
86-
v.value = 1
87-
b2.count_down
88-
b2.wait
89-
v.value
66+
it 'returns the new value' do
67+
v = ThreadLocalVar.new(14)
68+
expect(v.value = 2).to eq 2
9069
end
9170

92-
t2 = Thread.new do
93-
b1.count_down
94-
b1.wait
71+
it 'does not modify the initial value for other threads' do
72+
v = ThreadLocalVar.new(14)
9573
v.value = 2
96-
b2.count_down
97-
b2.wait
98-
v.value
74+
t = Thread.new { v.value }
75+
expect(t.value).to eq 14
9976
end
10077

101-
expect(t1.value).to eq 1
102-
expect(t2.value).to eq 2
78+
it 'does not modify the value for other threads' do
79+
v = ThreadLocalVar.new(14)
80+
v.value = 2
81+
82+
b1 = CountDownLatch.new(2)
83+
b2 = CountDownLatch.new(2)
84+
85+
t1 = Thread.new do
86+
b1.count_down
87+
b1.wait
88+
v.value = 1
89+
b2.count_down
90+
b2.wait
91+
v.value
92+
end
93+
94+
t2 = Thread.new do
95+
b1.count_down
96+
b1.wait
97+
v.value = 2
98+
b2.count_down
99+
b2.wait
100+
v.value
101+
end
102+
103+
expect(t1.value).to eq 1
104+
expect(t2.value).to eq 2
105+
end
103106
end
104107
end
105108
end

0 commit comments

Comments
 (0)