Skip to content

Commit 262bd58

Browse files
committed
Merge pull request #429 from ruby-concurrency/buggy-tests
Reliably testing concurrency abstractions will be the death of me.
2 parents ae66d27 + 413650f commit 262bd58

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

spec/concurrent/atomic/event_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ def subject.simulate_spurious_wake_up
163163
expect(latch.wait(0.1)).to be false
164164
end
165165

166-
it 'should resist to spurious wake ups with timeout' do
166+
it 'should resist spurious wake ups with timeout', buggy: true do
167167
latch = CountDownLatch.new(1)
168-
t = Thread.new{ subject.wait(0.3); latch.count_down }
168+
t = Thread.new{ subject.wait(0.5); latch.count_down }
169169
t.join(0.1)
170170

171171
subject.simulate_spurious_wake_up

spec/concurrent/exchanger_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
t1.kill
144144
end
145145

146-
it 'allows multiple firsts to cancel if necessary' do
146+
it 'allows multiple firsts to cancel if necessary', buggy: true do
147147
first_value = nil
148148
second_value = nil
149149
cancels = 3

spec/concurrent/executor/thread_pool_executor_shared.rb

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@
465465

466466
context ':caller_runs' do
467467

468-
subject do
468+
let(:executor) do
469469
described_class.new(
470470
min_threads: 1,
471471
max_threads: 1,
@@ -475,14 +475,20 @@
475475
)
476476
end
477477

478+
after(:each) do
479+
# need to replicate this w/i scope otherwise rspec may complain
480+
executor.kill
481+
executor.wait_for_termination(0.1)
482+
end
483+
478484
specify '#post does not create any new threads when the queue is at capacity' do
479485
trigger = Concurrent::Event.new
480486
initial = Thread.list.length
481487

482488
# Post several tasks to the executor. Has to be a new thread,
483489
# because it will start blocking once the queue fills up.
484490
Thread.new do
485-
5.times{ subject.post{ trigger.wait } }
491+
5.times{ executor.post{ trigger.wait } }
486492
end
487493

488494
expect(Thread.list.length).to be < initial + 1 + 5
@@ -494,32 +500,32 @@
494500
specify '#<< executes the task on the current thread when the queue is at capacity' do
495501
trigger = Concurrent::Event.new
496502
latch = Concurrent::CountDownLatch.new(5)
497-
subject.post{ trigger.wait }
498-
5.times{|i| subject << proc { latch.count_down } }
503+
executor.post{ trigger.wait }
504+
5.times{|i| executor << proc { latch.count_down } }
499505
latch.wait(0.1)
500506
trigger.set
501507
end
502508

503509
specify '#post executes the task on the current thread when the queue is at capacity' do
504510
trigger = Concurrent::Event.new
505511
latch = Concurrent::CountDownLatch.new(5)
506-
subject.post{ trigger.wait }
507-
5.times{|i| subject.post{ latch.count_down } }
512+
executor.post{ trigger.wait }
513+
5.times{|i| executor.post{ latch.count_down } }
508514
latch.wait(0.1)
509515
trigger.set
510516
end
511517

512518
specify '#post executes the task on the current thread when the executor is shutting down' do
513519
latch = Concurrent::CountDownLatch.new(1)
514-
subject.shutdown
515-
subject.post{ latch.count_down }
520+
executor.shutdown
521+
executor.post{ latch.count_down }
516522
latch.wait(0.1)
517523
end
518524

519525
specify '#<< executes the task on the current thread when the executor is shutting down' do
520526
latch = Concurrent::CountDownLatch.new(1)
521-
subject.shutdown
522-
subject << proc { latch.count_down }
527+
executor.shutdown
528+
executor << proc { latch.count_down }
523529
latch.wait(0.1)
524530
end
525531
end

spec/concurrent/executor/thread_pool_shared.rb

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,23 @@
8181
expect(subject.completed_task_count).to eq 0
8282
end
8383

84-
it 'returns the approximate number of tasks that have been completed thus far' do
85-
5.times{ subject.post{ raise StandardError } }
86-
5.times{ subject.post{ nil } }
87-
subject.post { latch.count_down }
88-
latch.wait(1)
89-
expect(subject.completed_task_count).to be > 1
90-
end
84+
unless Concurrent.on_jruby?
85+
86+
it 'returns the approximate number of tasks that have been completed thus far' do
87+
5.times{ subject.post{ raise StandardError } }
88+
5.times{ subject.post{ nil } }
89+
subject.post { latch.count_down }
90+
latch.wait(1)
91+
expect(subject.completed_task_count).to be > 1
92+
end
9193

92-
it 'returns the approximate number of tasks that were completed' do
93-
5.times{ subject.post{ raise StandardError } }
94-
5.times{ subject.post{ nil } }
95-
subject.shutdown
96-
subject.wait_for_termination(1)
97-
expect(subject.completed_task_count).to be > 1
94+
it 'returns the approximate number of tasks that were completed' do
95+
5.times{ subject.post{ raise StandardError } }
96+
5.times{ subject.post{ nil } }
97+
subject.shutdown
98+
subject.wait_for_termination(1)
99+
expect(subject.completed_task_count).to be > 1
100+
end
98101
end
99102
end
100103

0 commit comments

Comments
 (0)