Commit c0d698fa authored by Markus Koller's avatar Markus Koller

Merge branch 'bvl-fix-double-job-compression' into 'master'

Don't compress job arguments twice

See merge request gitlab-org/gitlab!66320
parents fbaf26a2 81be90b2
......@@ -99,6 +99,10 @@ module Gitlab
return job_args unless compress_mode?
return job_args if job_args.bytesize < @compression_threshold
# When a job was scheduled in the future, it runs through the middleware
# twice. Once on scheduling and once on queueing. No need to compress twice.
return job_args if ::Gitlab::SidekiqMiddleware::SizeLimiter::Compressor.compressed?(@job)
::Gitlab::SidekiqMiddleware::SizeLimiter::Compressor.compress(@job, job_args)
end
......
......@@ -230,11 +230,11 @@ RSpec.describe Gitlab::SidekiqMiddleware::SizeLimiter::Validator do
end
context 'in compress mode' do
let(:size_limit) { 50 }
let(:compression_threshold) { 30 }
let(:mode) { 'compress' }
context 'when job size is less than compression threshold' do
let(:size_limit) { 50 }
let(:compression_threshold) { 30 }
let(:job) { job_payload(a: 'a' * 10) }
it 'does not raise an exception' do
......@@ -244,8 +244,6 @@ RSpec.describe Gitlab::SidekiqMiddleware::SizeLimiter::Validator do
end
context 'when job size is bigger than compression threshold and less than size limit after compressed' do
let(:size_limit) { 50 }
let(:compression_threshold) { 30 }
let(:args) { { a: 'a' * 300 } }
let(:job) { job_payload(args) }
......@@ -260,9 +258,20 @@ RSpec.describe Gitlab::SidekiqMiddleware::SizeLimiter::Validator do
end
end
context 'when the job was already compressed' do
let(:job) do
job_payload({ a: 'a' * 10 })
.merge(Gitlab::SidekiqMiddleware::SizeLimiter::Compressor::COMPRESSED_KEY => true)
end
it 'does not compress the arguments again' do
expect(Gitlab::SidekiqMiddleware::SizeLimiter::Compressor).not_to receive(:compress)
expect { validate.call(TestSizeLimiterWorker, job) }.not_to raise_error
end
end
context 'when job size is bigger than compression threshold and bigger than size limit after compressed' do
let(:size_limit) { 50 }
let(:compression_threshold) { 30 }
let(:args) { { a: 'a' * 3000 } }
let(:job) { job_payload(args) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment