Add spec that proves trace can be recovered even if it had redis outage

This commit is contained in:
Shinya Maeda 2018-04-06 16:08:23 +09:00
parent eaf29ccec0
commit aaff5e452e
3 changed files with 30 additions and 0 deletions

View File

@ -52,6 +52,7 @@ module API
end
def job_token_valid?(job)
# binding.pry
token = (params[JOB_TOKEN_PARAM] || env[JOB_TOKEN_HEADER]).to_s
token && job.valid_token?(token)
end

View File

@ -2,6 +2,7 @@ require 'spec_helper'
describe API::Runner, :clean_gitlab_redis_shared_state do
include StubGitlabCalls
include ChunkedIOHelpers
let(:registration_token) { 'abcdefg123456' }
@ -865,6 +866,29 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
expect(response.status).to eq(403)
end
end
context 'when redis had an outage' do
it "recovers" do
# GitLab-Runner patchs
patch_the_trace
expect(job.reload.trace.raw).to eq 'BUILD TRACE appended appended'
# GitLab-Rails enxounters an outage on Redis
redis_shared_state_outage!
expect(job.reload.trace.raw).to eq ''
# GitLab-Runner patchs
patch_the_trace('hello', headers.merge({ 'Content-Range' => "28-32" }))
expect(response.status).to eq 202
expect(response.header).to have_key 'Range'
expect(response.header['Range']).to eq '0-0'
expect(job.reload.trace.raw).to eq ''
# GitLab-Runner re-patchs
patch_the_trace('BUILD TRACE appended appended hello')
expect(job.reload.trace.raw).to eq 'BUILD TRACE appended appended hello'
end
end
end
context 'when Runner makes a force-patch' do

View File

@ -8,4 +8,9 @@ module ChunkedIOHelpers
stub_const('Ci::JobTraceChunk::CHUNK_SIZE', size)
stub_const('Gitlab::Ci::Trace::ChunkedIO::CHUNK_SIZE', size)
end
def redis_shared_state_outage!
Gitlab::Redis::SharedState.with(&:flushall)
Sidekiq.redis(&:flushall)
end
end