diff options
author | Nick Thomas <nick@gitlab.com> | 2019-02-20 15:35:57 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-03-27 16:51:33 +0000 |
commit | 0e831b0b692f2988d3c84fc01a463b08afec05ad (patch) | |
tree | 3fdcb423db62141b2db2d2cc3f39986fb929c8af /spec/workers | |
parent | 98824f3e97e24a5d6cb0688167bc8411a74739fc (diff) | |
download | gitlab-ce-0e831b0b692f2988d3c84fc01a463b08afec05ad.tar.gz |
Allow external diffs to be used conditionally
Since external diffs are likely to be a bit slower than in-database
ones, add a mode that makes diffs external after they've been obsoleted
by events. This should strike a balance between performance and disk
space.
A background cron drives the majority of migrations, since diffs become
outdated through user actions.
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/migrate_external_diffs_worker_spec.rb | 25 | ||||
-rw-r--r-- | spec/workers/schedule_migrate_external_diffs_worker_spec.rb | 25 |
2 files changed, 50 insertions, 0 deletions
diff --git a/spec/workers/migrate_external_diffs_worker_spec.rb b/spec/workers/migrate_external_diffs_worker_spec.rb new file mode 100644 index 00000000000..88d48cad14b --- /dev/null +++ b/spec/workers/migrate_external_diffs_worker_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe MigrateExternalDiffsWorker do + let(:worker) { described_class.new } + let(:diff) { create(:merge_request).merge_request_diff } + + describe '#perform' do + it 'migrates the listed diff' do + expect_next_instance_of(MergeRequests::MigrateExternalDiffsService) do |instance| + expect(instance.diff).to eq(diff) + expect(instance).to receive(:execute) + end + + worker.perform(diff.id) + end + + it 'does nothing if the diff is missing' do + diff.destroy + + worker.perform(diff.id) + end + end +end diff --git a/spec/workers/schedule_migrate_external_diffs_worker_spec.rb b/spec/workers/schedule_migrate_external_diffs_worker_spec.rb new file mode 100644 index 00000000000..9d6fecc9f4e --- /dev/null +++ b/spec/workers/schedule_migrate_external_diffs_worker_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ScheduleMigrateExternalDiffsWorker do + include ExclusiveLeaseHelpers + + let(:worker) { described_class.new } + + describe '#perform' do + it 'triggers a scan for diffs to migrate' do + expect(MergeRequests::MigrateExternalDiffsService).to receive(:enqueue!) + + worker.perform + end + + it 'will not run if the lease is already taken' do + stub_exclusive_lease_taken('schedule_migrate_external_diffs_worker', timeout: 2.hours) + + expect(MergeRequests::MigrateExternalDiffsService).not_to receive(:enqueue!) + + worker.perform + end + end +end |