X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e34a96439f47fb34007587633f0210c93e116e76..b4fd2ab4e409e36f894c1fb27144e4fa2854f389:/services/api/test/functional/arvados/v1/jobs_controller_test.rb diff --git a/services/api/test/functional/arvados/v1/jobs_controller_test.rb b/services/api/test/functional/arvados/v1/jobs_controller_test.rb index 72a824ee50..07e7f840a1 100644 --- a/services/api/test/functional/arvados/v1/jobs_controller_test.rb +++ b/services/api/test/functional/arvados/v1/jobs_controller_test.rb @@ -101,107 +101,38 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase 'trigger file should be created when job is cancelled') end - test "cancelling a cancelled job stays cancelled" do - # We need to verify that "cancel" creates a trigger file, so first - # let's make sure there is no stale trigger file. - begin - File.unlink(Rails.configuration.crunch_refresh_trigger) - rescue Errno::ENOENT - end - - authorize_with :active - put :update, { - id: jobs(:running).uuid, - job: { - state: 'Cancelled' - } - } - job = JSON.parse(@response.body) - assert_not_nil job['cancelled_at'], 'cancelled again job did not stay cancelled' - assert_equal job['state'], 'Cancelled', 'cancelled again job state not cancelled' - end - - test "cancelling a cancelled job using cancelled_at stays cancelled" do - # We need to verify that "cancel" creates a trigger file, so first - # let's make sure there is no stale trigger file. - begin - File.unlink(Rails.configuration.crunch_refresh_trigger) - rescue Errno::ENOENT - end - - authorize_with :active - put :update, { - id: jobs(:running).uuid, - job: { - cancelled_at: Time.now - } - } - job = JSON.parse(@response.body) - assert_not_nil job['cancelled_at'], 'cancelled again job did not stay cancelled' - assert_equal job['state'], 'Cancelled', 'cancelled again job state not cancelled' - end - - test "cancelled job stays cancelled when state set to Running" do - # We need to verify that "cancel" creates a trigger file, so first - # let's make sure there is no stale trigger file. - begin - File.unlink(Rails.configuration.crunch_refresh_trigger) - rescue Errno::ENOENT - end - - authorize_with :active - put :update, { - id: jobs(:cancelled).uuid, - job: { - state: 'Running' - } - } - job = JSON.parse(@response.body) - assert_not_nil job['cancelled_at'], 'cancelled job did not stay cancelled when state set to running' - assert_equal job['state'], 'Cancelled', 'was able to change state to running for a cancelled job' - end - - test "cancelled job stays cancelled when state set to Complete" do - # We need to verify that "cancel" creates a trigger file, so first - # let's make sure there is no stale trigger file. - begin - File.unlink(Rails.configuration.crunch_refresh_trigger) - rescue Errno::ENOENT - end - - authorize_with :active - put :update, { - id: jobs(:cancelled).uuid, - job: { - state: 'Complete' - } - } - job = JSON.parse(@response.body) - assert_not_nil job['cancelled_at'], 'cancelled job did not stay cancelled when state set to complete' - assert_equal job['state'], 'Cancelled', 'was able to change state to complete for a cancelled job' - end + [ + [:put, :update, {job:{cancelled_at: Time.now}}, :success], + [:put, :update, {job:{cancelled_at: nil}}, :unprocessable_entity], + [:put, :update, {job:{state: 'Cancelled'}}, :success], + [:put, :update, {job:{state: 'Queued'}}, :unprocessable_entity], + [:put, :update, {job:{state: 'Running'}}, :unprocessable_entity], + [:put, :update, {job:{state: 'Failed'}}, :unprocessable_entity], + [:put, :update, {job:{state: 'Complete'}}, :unprocessable_entity], + [:post, :cancel, {}, :success], + ].each do |http_method, action, params, expected_response| + test "cancelled job stays cancelled after #{[http_method, action, params].inspect}" do + # We need to verify that "cancel" creates a trigger file, so first + # let's make sure there is no stale trigger file. + begin + File.unlink(Rails.configuration.crunch_refresh_trigger) + rescue Errno::ENOENT + end - test "cancelled job stays cancelled when state set to Failed" do - # We need to verify that "cancel" creates a trigger file, so first - # let's make sure there is no stale trigger file. - begin - File.unlink(Rails.configuration.crunch_refresh_trigger) - rescue Errno::ENOENT + authorize_with :active + self.send http_method, action, { id: jobs(:cancelled).uuid }.merge(params) + assert_response expected_response + if expected_response == :success + job = json_response + assert_not_nil job['cancelled_at'], 'job cancelled again using #{attribute}=#{value} did not have cancelled_at value' + assert_equal job['state'], 'Cancelled', 'cancelled again job state changed when updated using using #{attribute}=#{value}' + end + # Verify database record still says Cancelled + assert_equal 'Cancelled', Job.find(jobs(:cancelled).id).state, 'job was un-cancelled' end - - authorize_with :active - put :update, { - id: jobs(:cancelled).uuid, - job: { - state: 'Failed' - } - } - job = JSON.parse(@response.body) - assert_not_nil job['cancelled_at'], 'cancelled job did not stay cancelled when state set to failed' - assert_equal job['state'], 'Cancelled', 'was able to change state to failed for a cancelled job' end - test "cancelled to any other state change results in error" do + test "cancelled job updated to any other state change results in error" do # We need to verify that "cancel" creates a trigger file, so first # let's make sure there is no stale trigger file. begin