Skip to content

Commit 90ad632

Browse files
committed
Refactored brittle thread pool #overload_policy :caller_runs tests
1 parent 276483c commit 90ad632

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

spec/concurrent/ruby_thread_pool_executor_spec.rb

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,33 @@ module Concurrent
122122
end
123123

124124
specify '#post does not create any new threads when the queue is at capacity' do
125-
2.times{ subject.post{ sleep(1) } }
126-
sleep(0.1)
127-
expected = Thread.list.length
128-
subject.post{ nil }
129-
Thread.list.length.should eq expected
125+
initial = Thread.list.length
126+
5.times{ subject.post{ sleep(0.1) } }
127+
Thread.list.length.should < initial + 5
128+
end
129+
130+
specify '#post executes the task on the current thread when the queue is at capacity' do
131+
subject.should_receive(:handle_overflow).with(any_args).at_least(:once)
132+
5.times{ subject.post{ sleep(0.1) } }
130133
end
131134

132135
specify '#post executes the task on the current thread when the queue is at capacity' do
133-
2.times{ subject.post{ sleep(1) } }
136+
bucket = []
137+
5.times{|i| subject.post{ bucket.push(i) } }
134138
sleep(0.1)
135-
expected = false
136-
subject.post{ expected = true }
137-
expected.should be_true
139+
bucket.sort.should eq [0, 1, 2, 3, 4]
138140
end
139141

140142
specify '#<< executes the task on the current thread when the queue is at capacity' do
141-
2.times{ subject.post{ sleep(1) } }
143+
subject.should_receive(:handle_overflow).with(any_args).at_least(:once)
144+
5.times{ subject << proc { sleep(0.1) } }
145+
end
146+
147+
specify '#post executes the task on the current thread when the queue is at capacity' do
148+
bucket = []
149+
5.times{|i| subject << proc { bucket.push(i) } }
142150
sleep(0.1)
143-
expected = false
144-
subject << proc { expected = true }
145-
expected.should be_true
151+
bucket.sort.should eq [0, 1, 2, 3, 4]
146152
end
147153
end
148154
end

0 commit comments

Comments
 (0)