Skip to content

Commit fcd5886

Browse files
committed
Stabilize
1 parent 7bab699 commit fcd5886

File tree

6 files changed

+47
-33
lines changed

6 files changed

+47
-33
lines changed

spec/concurrent/agent_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ def update(time, old_value, new_value)
447447
end
448448

449449
it 'posts to the global fast executor' do
450-
expect(Concurrent.global_fast_executor).to receive(:post).with(any_args).and_call_original
451450
subject = Agent.new(0)
451+
expect(subject).to receive(:enqueue_action_job).with(anything, anything, Concurrent.global_fast_executor).and_call_original
452452
subject.send { nil }
453453
end
454454

@@ -476,8 +476,8 @@ def update(time, old_value, new_value)
476476
end
477477

478478
it 'posts to the global fast executor' do
479-
expect(Concurrent.global_fast_executor).to receive(:post).with(any_args).and_call_original
480479
subject = Agent.new(0)
480+
expect(subject).to receive(:enqueue_action_job).with(anything, anything, Concurrent.global_fast_executor).and_call_original
481481
subject.send! { nil }
482482
end
483483

@@ -503,8 +503,8 @@ def update(time, old_value, new_value)
503503
end
504504

505505
it 'posts to the global io executor' do
506-
expect(Concurrent.global_io_executor).to receive(:post).with(any_args).and_call_original
507506
subject = Agent.new(0)
507+
expect(subject).to receive(:enqueue_action_job).with(anything, anything, Concurrent.global_io_executor).and_call_original
508508
subject.send_off { nil }
509509
end
510510

@@ -532,8 +532,8 @@ def update(time, old_value, new_value)
532532
end
533533

534534
it 'posts to the global io executor' do
535-
expect(Concurrent.global_io_executor).to receive(:post).with(any_args).and_call_original
536535
subject = Agent.new(0)
536+
expect(subject).to receive(:enqueue_action_job).with(anything, anything, Concurrent.global_io_executor).and_call_original
537537
subject.send_off! { nil }
538538
end
539539

@@ -615,8 +615,8 @@ def update(time, old_value, new_value)
615615
end
616616

617617
it 'posts to the global io executor' do
618-
expect(Concurrent.global_io_executor).to receive(:post).with(any_args).and_call_original
619618
subject = Agent.new(0)
619+
expect(subject).to receive(:enqueue_action_job).with(anything, anything, Concurrent.global_io_executor).and_call_original
620620
subject.post { nil }
621621
end
622622

@@ -1121,7 +1121,7 @@ def update(time, old_value, new_value)
11211121
agents = 3.times.collect { Agent.new(0) }
11221122
agents.each { |agent| agent.send_via(executor, latch) { |_, l| l.wait(1) } }
11231123
in_thread { latch.count_down }
1124-
ok = Agent.await_for(1, *agents)
1124+
ok = Agent.await_for(5, *agents)
11251125
expect(ok).to be true
11261126
end
11271127

@@ -1146,7 +1146,7 @@ def update(time, old_value, new_value)
11461146
agents = 3.times.collect { Agent.new(0) }
11471147
agents.each { |agent| agent.send_via(executor, latch) { |_, l| l.wait(1) } }
11481148
in_thread { latch.count_down }
1149-
ok = Agent.await_for!(1, *agents)
1149+
ok = Agent.await_for!(5, *agents)
11501150
expect(ok).to be true
11511151
end
11521152

spec/concurrent/atomic/cyclic_barrier_spec.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,16 @@ module Concurrent
196196

197197
context '#broken barrier' do
198198
it 'should not accept new threads' do
199-
t = in_thread { barrier.wait(0.1) }
200-
t.join(0.2)
199+
t = in_thread { barrier.wait(0.01) }
200+
join_with t
201201

202202
expect(barrier).to be_broken
203-
204203
expect(barrier.wait).to be_falsey
205204
end
206205

207206
it 'can be reset' do
208-
t = in_thread { barrier.wait(0.1) }
209-
t.join(0.2)
207+
t = in_thread { barrier.wait(0.01) }
208+
join_with t
210209

211210
expect(barrier).to be_broken
212211

spec/concurrent/atomic/event_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ module Concurrent
139139
end
140140

141141
it 'behaves appropriately if wait begins while #set is processing' do
142+
subject = subject()
142143
subject.reset
143144
latch = CountDownLatch.new(5)
144145
5.times{ in_thread{ subject.wait(5) } }

spec/concurrent/map_spec.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,31 +282,33 @@ module Concurrent
282282
compute_finished.count_down
283283
end
284284

285-
getter_threads = (1..getters_count).map do
285+
getter_threads = getters_count.times.map do
286286
in_thread do
287287
getters_started.count_down
288288
inserted_keys.each do |inserted_key|
289-
expect(true).to eq @cache.key?(inserted_key)
290-
expect(1).to eq @cache[inserted_key]
289+
expect(@cache.key?(inserted_key)).to eq true
290+
expect(@cache[inserted_key]).to eq 1
291291
end
292292
expect(false).to eq @cache.key?(key)
293+
293294
compute_started.wait
295+
294296
inserted_keys.each do |inserted_key|
295-
expect(true).to eq @cache.key?(inserted_key)
296-
expect(1).to eq @cache[inserted_key]
297+
expect(@cache.key?(inserted_key)).to eq true
298+
expect(@cache[inserted_key]).to eq 1
297299
end
298-
expect(false).to eq @cache.key?(key)
299-
expect(nil).to eq @cache[key]
300+
expect(@cache.key?(key)).to eq false
301+
expect(@cache[key]).to eq nil
300302
getters_finished.count_down
303+
301304
compute_finished.wait
302-
expect(true).to eq @cache.key?(key)
303-
expect(1).to eq @cache[key]
305+
306+
expect(@cache.key?(key)).to eq true
307+
expect(@cache[key]).to eq 1
304308
end
305309
end
306310

307-
(getter_threads + [computer_thread]).map do |t|
308-
expect(t.join(2)).to be_truthy
309-
end # asserting no deadlocks
311+
join_with getter_threads + [computer_thread]
310312
inserted_keys << key
311313
end
312314
end

spec/concurrent/synchronization_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def ns_initialize
125125
subject.wait
126126
end
127127
t2 = in_thread { Thread.pass until t1.status == 'sleep' }
128-
join_with t2, 5
128+
join_with t2
129129
end
130130

131131
it 'allows the sleeping thread to be killed' do
@@ -136,7 +136,7 @@ def ns_initialize
136136
sleep 0.1
137137
t.kill
138138
sleep 0.1
139-
expect(t.status).to eq false
139+
expect(t.join).not_to eq nil
140140
expect(t.alive?).to eq false
141141
end
142142

@@ -148,7 +148,7 @@ def ns_initialize
148148
subject.synchronize {} # it will deadlock here if #wait doesn't release lock
149149
t2
150150
end
151-
join_with t1, 5
151+
join_with t1
152152
expect(t1.value.status).to eq 'sleep'
153153
end
154154

@@ -159,7 +159,7 @@ def ns_initialize
159159
subject.synchronize {} # it will deadlock here if #wait doesn't release lock
160160
t2
161161
end
162-
join_with t1, 5
162+
join_with t1
163163
expect(t1.value.status).to eq 'sleep'
164164
end
165165
end

spec/support/example_group_extensions.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ def monotonic_interval
2828

2929
def in_thread(*args, &block)
3030
@created_threads ||= Queue.new
31-
@created_threads.push t = Thread.new(*args, &block)
32-
t
31+
new_thread = Thread.new(*args) do |*args, &b|
32+
Thread.abort_on_exception = true
33+
block.call *args, &b
34+
end
35+
@created_threads.push new_thread
36+
new_thread
3337
end
3438

35-
def join_with(threads, timeout = 0.1)
36-
Array(threads).each { |t| expect(t.join(timeout)).not_to eq nil }
39+
def join_with(threads, timeout = 5)
40+
threads = Array(threads)
41+
threads.each do |t|
42+
joined_thread = t.join(timeout * threads.size)
43+
expect(joined_thread).not_to eq nil
44+
end
3745
end
3846
end
3947
end
@@ -42,10 +50,14 @@ class RSpec::Core::ExampleGroup
4250
include Concurrent::TestHelpers
4351
extend Concurrent::TestHelpers
4452

53+
before :each do
54+
expect(@created_threads.nil? || @created_threads.empty?).to be_truthy
55+
end
56+
4557
after :each do
4658
while (thread = (@created_threads.pop(true) rescue nil))
4759
thread.kill
48-
expect(thread.join(0.25)).not_to eq nil
60+
expect(thread.join(0.25)).not_to be_nil
4961
end
5062
end
5163
end

0 commit comments

Comments
 (0)