summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2018-06-07 17:27:26 +0200
committerTomasz Maczukin <tomasz@maczukin.pl>2018-06-07 18:45:48 +0200
commita6a900256e194c28d8342db9c2d67df784877c14 (patch)
treefabd5896948584c4c787aca84e59af166b1e13ec /spec
parent6fafc63117a9382ee088e364e83431ebd1b63a4a (diff)
downloadgitlab-ce-a6a900256e194c28d8342db9c2d67df784877c14.tar.gz
Change update entrypoint instead of adding new keep-alive one
Diffstat (limited to 'spec')
-rw-r--r--spec/requests/api/runner_spec.rb84
1 files changed, 26 insertions, 58 deletions
diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb
index c93612d7ada..57d238ff79b 100644
--- a/spec/requests/api/runner_spec.rb
+++ b/spec/requests/api/runner_spec.rb
@@ -816,6 +816,18 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
expect(job.reload.trace.raw).to eq 'BUILD TRACE'
end
+
+ context 'when running state is sent' do
+ it 'updates update_at value' do
+ expect { update_job_after_time }.to change { job.reload.updated_at }
+ end
+ end
+
+ context 'when other state is sent' do
+ it "doesn't update update_at value" do
+ expect { update_job_after_time(20.minutes, state: 'success') }.not_to change { job.reload.updated_at }
+ end
+ end
end
context 'when job has been erased' do
@@ -838,6 +850,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
update_job(state: 'success', trace: 'BUILD TRACE UPDATED')
expect(response).to have_gitlab_http_status(403)
+ expect(response.header['Job-Status']).to eq 'failed'
expect(job.trace.raw).to eq 'Job failed'
expect(job).to be_failed
end
@@ -847,66 +860,10 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
new_params = params.merge(token: token)
put api("/jobs/#{job.id}"), new_params
end
- end
-
- describe 'POST /api/v4/jobs/:id/keep-alive' do
- let(:job) { create(:ci_build, :running, :trace_live, runner_id: runner.id, pipeline: pipeline) }
- let(:headers) { { API::Helpers::Runner::JOB_TOKEN_HEADER => job.token, 'Content-Type' => 'text/plain' } }
- let(:update_interval) { 30.seconds }
-
- it 'returns correct response' do
- keep_alive_job
-
- expect(response.status).to eq 200
- expect(response.header).to have_key 'Job-Status'
- end
-
- it 'updates updated_at value' do
- expect { keep_alive_job }.to change { job.updated_at }
- end
-
- context 'when project for the build has been deleted' do
- let(:job) do
- create(:ci_build, :running, :trace_live, runner_id: runner.id, pipeline: pipeline) do |job|
- job.project.update(pending_delete: true)
- end
- end
-
- it 'responds with forbidden' do
- keep_alive_job
-
- expect(response.status).to eq(403)
- end
- end
- context 'when job has been canceled' do
- before do
- job.cancel
- end
-
- it 'returns job-status=canceled header' do
- keep_alive_job
-
- expect(response.status).to eq 200
- expect(response.header['Job-Status']).to eq('canceled')
- end
- end
-
- context 'when job has been errased' do
- let(:job) { create(:ci_build, runner_id: runner.id, erased_at: Time.now) }
-
- it 'rresponds with forbidden' do
- keep_alive_job
-
- expect(response.status).to eq 403
- end
- end
-
- def keep_alive_job(token = job.token, **params)
- new_params = params.merge(token: token)
+ def update_job_after_time(update_interval = 20.minutes, state = 'running')
Timecop.travel(job.updated_at + update_interval) do
- post api("/jobs/#{job.id}/keep-alive"), new_params
- job.reload
+ update_job(job.token, state: state)
end
end
end
@@ -1041,6 +998,17 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end
end
end
+
+ context 'when the job is canceled' do
+ before do
+ job.cancel
+ patch_the_trace
+ end
+
+ it 'receives status in header' do
+ expect(response.header['Job-Status']).to eq 'canceled'
+ end
+ end
end
context 'when Runner makes a force-patch' do