Skip to content

Commit 6bd961c

Browse files
committed
Fixes from testing under JRuby
1 parent 5148d10 commit 6bd961c

File tree

3 files changed

+193
-191
lines changed

3 files changed

+193
-191
lines changed

lib/concurrent/executor/executor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ module JavaExecutor
252252
}.freeze
253253

254254
# @!macro executor_method_post
255-
def post(*args)
255+
def post(*args, &task)
256256
raise ArgumentError.new('no block given') unless block_given?
257257
return handle_fallback(*args, &task) unless running?
258258
executor_submit = @executor.java_method(:submit, [Runnable.java_class])

spec/concurrent/executor/ruby_thread_pool_executor_spec.rb

Lines changed: 0 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -48,195 +48,5 @@ module Concurrent
4848
expect(subject.remaining_capacity).to be < expected_max
4949
end
5050
end
51-
52-
context '#fallback_policy' do
53-
54-
let!(:min_threads){ 1 }
55-
let!(:max_threads){ 1 }
56-
let!(:idletime){ 60 }
57-
let!(:max_queue){ 1 }
58-
59-
context ':abort' do
60-
61-
subject do
62-
described_class.new(
63-
min_threads: min_threads,
64-
max_threads: max_threads,
65-
idletime: idletime,
66-
max_queue: max_queue,
67-
fallback_policy: :abort
68-
)
69-
end
70-
71-
specify '#post raises an error when the queue is at capacity' do
72-
expect {
73-
100.times{ subject.post{ sleep(1) } }
74-
}.to raise_error(Concurrent::RejectedExecutionError)
75-
end
76-
77-
specify '#<< raises an error when the queue is at capacity' do
78-
expect {
79-
100.times{ subject << proc { sleep(1) } }
80-
}.to raise_error(Concurrent::RejectedExecutionError)
81-
end
82-
83-
specify '#post raises an error when the executor is shutting down' do
84-
expect {
85-
subject.shutdown; subject.post{ sleep(1) }
86-
}.to raise_error(Concurrent::RejectedExecutionError)
87-
end
88-
89-
specify '#<< raises an error when the executor is shutting down' do
90-
expect {
91-
subject.shutdown; subject << proc { sleep(1) }
92-
}.to raise_error(Concurrent::RejectedExecutionError)
93-
end
94-
95-
specify 'a #post task is never executed when the queue is at capacity' do
96-
executed = Concurrent::AtomicFixnum.new(0)
97-
10.times do
98-
begin
99-
subject.post{ executed.increment; sleep(0.1) }
100-
rescue
101-
end
102-
end
103-
sleep(0.2)
104-
expect(executed.value).to be < 10
105-
end
106-
107-
specify 'a #<< task is never executed when the queue is at capacity' do
108-
executed = Concurrent::AtomicFixnum.new(0)
109-
10.times do
110-
begin
111-
subject << proc { executed.increment; sleep(0.1) }
112-
rescue
113-
end
114-
end
115-
sleep(0.2)
116-
expect(executed.value).to be < 10
117-
end
118-
end
119-
120-
context ':discard' do
121-
122-
subject do
123-
described_class.new(
124-
min_threads: min_threads,
125-
max_threads: max_threads,
126-
idletime: idletime,
127-
max_queue: max_queue,
128-
fallback_policy: :discard
129-
)
130-
end
131-
132-
specify 'a #post task is never executed when the queue is at capacity' do
133-
executed = Concurrent::AtomicFixnum.new(0)
134-
1000.times do
135-
subject.post{ executed.increment }
136-
end
137-
sleep(0.1)
138-
expect(executed.value).to be < 1000
139-
end
140-
141-
specify 'a #<< task is never executed when the queue is at capacity' do
142-
executed = Concurrent::AtomicFixnum.new(0)
143-
1000.times do
144-
subject << proc { executed.increment }
145-
end
146-
sleep(0.1)
147-
expect(executed.value).to be < 1000
148-
end
149-
150-
specify 'a #post task is never executed when the executor is shutting down' do
151-
executed = Concurrent::AtomicFixnum.new(0)
152-
subject.shutdown
153-
subject.post{ executed.increment }
154-
sleep(0.1)
155-
expect(executed.value).to be 0
156-
end
157-
158-
specify 'a #<< task is never executed when the executor is shutting down' do
159-
executed = Concurrent::AtomicFixnum.new(0)
160-
subject.shutdown
161-
subject << proc { executed.increment }
162-
sleep(0.1)
163-
expect(executed.value).to be 0
164-
end
165-
166-
specify '#post returns false when the executor is shutting down' do
167-
executed = Concurrent::AtomicFixnum.new(0)
168-
subject.shutdown
169-
ret = subject.post{ executed.increment }
170-
expect(ret).to be false
171-
end
172-
end
173-
174-
context ':caller_runs' do
175-
176-
subject do
177-
described_class.new(
178-
min_threads: 1,
179-
max_threads: 1,
180-
idletime: idletime,
181-
max_queue: 1,
182-
fallback_policy: :caller_runs
183-
)
184-
end
185-
186-
specify '#post does not create any new threads when the queue is at capacity' do
187-
initial = Thread.list.length
188-
5.times{ subject.post{ sleep(0.1) } }
189-
expect(Thread.list.length).to be < initial + 5
190-
end
191-
192-
specify '#<< executes the task on the current thread when the queue is at capacity' do
193-
expect(subject).to receive(:handle_fallback).with(any_args).at_least(:once)
194-
5.times{ subject << proc { sleep(0.1) } }
195-
end
196-
197-
specify '#post executes the task on the current thread when the queue is at capacity' do
198-
latch = Concurrent::CountDownLatch.new(5)
199-
subject.post{ sleep(1) }
200-
5.times{|i| subject.post{ latch.count_down } }
201-
latch.wait(0.1)
202-
end
203-
204-
specify '#post executes the task on the current thread when the executor is shutting down' do
205-
latch = Concurrent::CountDownLatch.new(1)
206-
subject.shutdown
207-
subject.post{ latch.count_down }
208-
latch.wait(0.1)
209-
end
210-
211-
specify '#<< executes the task on the current thread when the executor is shutting down' do
212-
latch = Concurrent::CountDownLatch.new(1)
213-
subject.shutdown
214-
subject << proc { latch.count_down }
215-
latch.wait(0.1)
216-
end
217-
end
218-
end
219-
220-
context '#fallback_policy' do
221-
context ':caller_runs is honoured even if the old fallback_policy arg is used' do
222-
223-
subject do
224-
described_class.new(
225-
min_threads: 1,
226-
max_threads: 1,
227-
idletime: 60,
228-
max_queue: 1,
229-
fallback_policy: :caller_runs
230-
)
231-
end
232-
233-
specify '#<< executes the task on the current thread when the executor is shutting down' do
234-
latch = Concurrent::CountDownLatch.new(1)
235-
subject.shutdown
236-
subject << proc { latch.count_down }
237-
latch.wait(0.1)
238-
end
239-
end
240-
end
24151
end
24252
end

0 commit comments

Comments
 (0)