Skip to content

Commit cf61bcc

Browse files
committed
Don't drain queue before executing members during shutdown
1 parent 1685532 commit cf61bcc

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/concurrent/executor/ruby_thread_pool_executor.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ def execute(*args, &task)
172172

173173
# @!visibility private
174174
def shutdown_execution
175-
@queue.clear
176175
if @pool.empty?
177176
stopped_event.set
178177
else

spec/concurrent/executor/thread_pool_shared.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,36 @@
100100
end
101101
end
102102

103+
context '#shutdown followed by #wait_for_termination' do
104+
it "allows in-progress tasks to complete" do
105+
@expected = false
106+
subject.post{ sleep 0.1; @expected = true }
107+
subject.shutdown
108+
subject.wait_for_termination(1)
109+
@expected.should be_true
110+
end
111+
112+
it 'allows pending tasks to complete' do
113+
@expected = false
114+
subject.post{ sleep(0.1) }
115+
subject.post{ sleep(0.1); @expected = true }
116+
subject.shutdown
117+
subject.wait_for_termination(1)
118+
@expected.should be_true
119+
end
120+
121+
it "stops accepting/running new tasks" do
122+
@expected = :start
123+
subject.post{ sleep(0.1) }
124+
subject.post{ sleep(0.1); @expected = :should_be_run }
125+
subject.shutdown
126+
subject.post{ @expected = :should_not_be_run }
127+
subject.wait_for_termination(1)
128+
@expected.should == :should_be_run
129+
end
130+
end
131+
132+
103133
context '#kill' do
104134

105135
it 'stops accepting new tasks' do

0 commit comments

Comments
 (0)