added a null check, removed setting status to used due to test problems, fixed mocking of container object.

This commit is contained in:
Ralf Teusner
2015-04-22 11:38:07 +02:00
parent e448e403ba
commit a7087824b1
2 changed files with 15 additions and 11 deletions

View File

@ -20,7 +20,9 @@ class DockerContainerPool
end end
def self.create_container(execution_environment) def self.create_container(execution_environment)
DockerClient.create_container(execution_environment) container = DockerClient.create_container(execution_environment)
container.status = 'available'
container
end end
def self.return_container(container, execution_environment) def self.return_container(container, execution_environment)
@ -32,7 +34,8 @@ class DockerContainerPool
if config[:active] if config[:active]
container = @containers[execution_environment.id].try(:shift) || nil container = @containers[execution_environment.id].try(:shift) || nil
if((Time.now - container.start_time).to_i.abs > TIME_TILL_RESTART) if(!container.nil?)
if ((Time.now - container.start_time).to_i.abs > TIME_TILL_RESTART)
# remove container from @all_containers # remove container from @all_containers
@all_containers[execution_environment.id]-=[container] @all_containers[execution_environment.id]-=[container]
@ -43,7 +46,8 @@ class DockerContainerPool
container = create_container(@execution_environment) container = create_container(@execution_environment)
@all_containers[execution_environment.id]+=[container] @all_containers[execution_environment.id]+=[container]
end end
container.status = 'used' #container.status = 'used'
end
container container
else else

View File

@ -1,7 +1,7 @@
require 'rails_helper' require 'rails_helper'
describe DockerContainerPool do describe DockerContainerPool do
let(:container) { double } let(:container) { double(:start_time => Time.now, :status => 'available') }
def reload_class def reload_class
load('docker_container_pool.rb') load('docker_container_pool.rb')