diff options
author | Nikhil Benesch <nikhil.benesch@gmail.com> | 2014-03-09 22:57:21 -0400 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2014-05-13 15:21:15 -0700 |
commit | 89d5d20dcd494c7d42a1f24f8a3ab7712735267e (patch) | |
tree | fbcaa2b854d0dc54405485ec9fa063d52e4ad060 /spec/unit/util | |
parent | bea3c04f0bf8f89c637cc8073825188acb095bff (diff) | |
download | chef-89d5d20dcd494c7d42a1f24f8a3ab7712735267e.tar.gz |
CHEF-4423: extract cookbook upload threaded queue into utility class
Diffstat (limited to 'spec/unit/util')
-rw-r--r-- | spec/unit/util/threaded_job_queue_spec.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/unit/util/threaded_job_queue_spec.rb b/spec/unit/util/threaded_job_queue_spec.rb new file mode 100644 index 0000000000..a199937639 --- /dev/null +++ b/spec/unit/util/threaded_job_queue_spec.rb @@ -0,0 +1,51 @@ +# Copyright:: Copyright (c) 2014 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'spec_helper' + +class WorkerThreadError < StandardError +end + +describe Chef::Util::ThreadedJobQueue do + let(:queue) { Chef::Util::ThreadedJobQueue.new } + + it "should pass mutex to jobs with an arity of 1" do + job = double() + job.should_receive(:arity).at_least(:once).and_return(1) + job.should_receive(:call).exactly(5).times.with(an_instance_of(Mutex)) + + 5.times { queue << job } + queue.process + end + + it "should pass nothing to jobs with an arity of 0" do + job = double() + job.should_receive(:arity).at_least(:once).and_return(0) + job.should_receive(:call).exactly(5).times.with(no_args) + + 5.times { queue << job } + queue.process + end + + it "should use specified number of threads" do + Thread.should_receive(:new).exactly(7).times.and_call_original + queue.process(7) + end + + it "should propagate exceptions to the main thread" do + queue << lambda { raise WorkerThreadError } + lambda { queue.process }.should raise_error(WorkerThreadError) + end +end |