From fb92d382ac120807bd3fe09863c3e70a04498f92 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Tue, 9 Nov 2021 17:37:11 +0100 Subject: [PATCH] Skip verification of Docker image if pool size is empty --- app/models/execution_environment.rb | 3 ++- spec/controllers/execution_environments_controller_spec.rb | 4 ++-- spec/models/execution_environment_spec.rb | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/models/execution_environment.rb b/app/models/execution_environment.rb index 1b3342e5..2f16db6b 100644 --- a/app/models/execution_environment.rb +++ b/app/models/execution_environment.rb @@ -78,7 +78,8 @@ class ExecutionEnvironment < ApplicationRecord end def validate_docker_image? - docker_image.present? && !Rails.env.test? + # We only validate the code execution with the provided image if there is at least one container to test with. + pool_size.positive? && docker_image.present? && !Rails.env.test? end def working_docker_image? diff --git a/spec/controllers/execution_environments_controller_spec.rb b/spec/controllers/execution_environments_controller_spec.rb index 001f1fa4..32acd572 100644 --- a/spec/controllers/execution_environments_controller_spec.rb +++ b/spec/controllers/execution_environments_controller_spec.rb @@ -13,7 +13,7 @@ describe ExecutionEnvironmentsController do describe 'POST #create' do context 'with a valid execution environment' do - let(:perform_request) { proc { post :create, params: {execution_environment: FactoryBot.build(:ruby).attributes} } } + let(:perform_request) { proc { post :create, params: {execution_environment: FactoryBot.build(:ruby, pool_size: 1).attributes} } } before do allow(Rails.env).to receive(:test?).and_return(false, true) @@ -186,7 +186,7 @@ describe ExecutionEnvironmentsController do runner = instance_double 'runner' allow(Runner).to receive(:for).and_return(runner) allow(runner).to receive(:execute_command).and_return({}) - put :update, params: {execution_environment: FactoryBot.attributes_for(:ruby), id: execution_environment.id} + put :update, params: {execution_environment: FactoryBot.attributes_for(:ruby, pool_size: 1), id: execution_environment.id} end expect_assigns(docker_images: Array) diff --git a/spec/models/execution_environment_spec.rb b/spec/models/execution_environment_spec.rb index 8bfb0b07..4a6e2ff3 100644 --- a/spec/models/execution_environment_spec.rb +++ b/spec/models/execution_environment_spec.rb @@ -138,8 +138,14 @@ describe ExecutionEnvironment do expect(execution_environment.send(:validate_docker_image?)).to be false end + it 'is false when the pool size is empty' do + expect(execution_environment.pool_size).to be 0 + expect(execution_environment.send(:validate_docker_image?)).to be false + end + it 'is true otherwise' do execution_environment.docker_image = FactoryBot.attributes_for(:ruby)[:docker_image] + execution_environment.pool_size = 1 allow(Rails.env).to receive(:test?).and_return(false) expect(execution_environment.send(:validate_docker_image?)).to be true end