diff --git a/config/docker.yml.erb b/config/docker.yml.erb index 68d50367..cefb8ba7 100644 --- a/config/docker.yml.erb +++ b/config/docker.yml.erb @@ -2,7 +2,8 @@ default: &default connection_timeout: 3 pool: active: false - interval: 60 + interval: 15 + maximum_refill_count: 32 ports: !ruby/range 4500..4600 development: diff --git a/lib/docker_container_pool.rb b/lib/docker_container_pool.rb index a2029447..b0ff2bc8 100644 --- a/lib/docker_container_pool.rb +++ b/lib/docker_container_pool.rb @@ -36,7 +36,7 @@ class DockerContainerPool def self.refill ExecutionEnvironment.all.each do |execution_environment| - refill_count = execution_environment.pool_size - @containers[execution_environment.id].length + refill_count = [execution_environment.pool_size - @containers[execution_environment.id].length, config[:maximum_refill_count]].min if refill_count > 0 Concurrent::Future.execute do @containers[execution_environment.id] += refill_count.times.map { create_container(execution_environment) } diff --git a/spec/lib/docker_container_pool_spec.rb b/spec/lib/docker_container_pool_spec.rb index 08d70660..2b322f27 100644 --- a/spec/lib/docker_container_pool_spec.rb +++ b/spec/lib/docker_container_pool_spec.rb @@ -91,7 +91,16 @@ describe DockerContainerPool do end context 'with something to refill' do - before(:each) { @execution_environment.update(pool_size: 1) } + let(:maximum_refill_count) { 5 } + before(:each) { @execution_environment.update(pool_size: 10) } + + it 'complies with the maximum batch size' do + expect(DockerContainerPool::config).to receive(:[]).with(:maximum_refill_count).and_return(maximum_refill_count) + expect_any_instance_of(Concurrent::Future).to receive(:execute) do |future| + expect(DockerContainerPool).to receive(:create_container).with(@execution_environment).exactly(maximum_refill_count).times + future.instance_variable_get(:@task).call + end + end it 'works asynchronously' do expect(Concurrent::Future).to receive(:execute)