diff options
author | Stan Hu <stanhu@gmail.com> | 2018-08-06 19:16:09 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-08-06 19:16:09 +0300 |
commit | 964d9f431f64754f171c5c523309417447c2ee71 (patch) | |
tree | d9d06c1ba2397ce9717a8ce0b01deb96d2bcce6b /spec/workers | |
parent | b4415c01740430cef58baf9bb0cbda2fb1055edb (diff) | |
parent | 1e5192cc8c2ebd3e0d740f3a044b7f5e4c086730 (diff) |
Merge branch 'background-migrations-system-load' into 'master'
Respond to DB health in background migrations
See merge request gitlab-org/gitlab-ce!20720
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/background_migration_worker_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/workers/background_migration_worker_spec.rb b/spec/workers/background_migration_worker_spec.rb index d67e7698635..3bd072e7125 100644 --- a/spec/workers/background_migration_worker_spec.rb +++ b/spec/workers/background_migration_worker_spec.rb @@ -3,6 +3,12 @@ require 'spec_helper' describe BackgroundMigrationWorker, :sidekiq, :clean_gitlab_redis_shared_state do let(:worker) { described_class.new } + describe '.minimum_interval' do + it 'returns 2 minutes' do + expect(described_class.minimum_interval).to eq(2.minutes.to_i) + end + end + describe '.perform' do it 'performs a background migration' do expect(Gitlab::BackgroundMigration) @@ -28,5 +34,51 @@ describe BackgroundMigrationWorker, :sidekiq, :clean_gitlab_redis_shared_state d worker.perform('Foo', [10, 20]) end + + it 'reschedules a migration if the database is not healthy' do + allow(worker) + .to receive(:always_perform?) + .and_return(false) + + allow(worker) + .to receive(:healthy_database?) + .and_return(false) + + expect(described_class) + .to receive(:perform_in) + .with(a_kind_of(Numeric), 'Foo', [10, 20]) + + worker.perform('Foo', [10, 20]) + end + end + + describe '#healthy_database?' do + context 'using MySQL', :mysql do + it 'returns true' do + expect(worker.healthy_database?).to eq(true) + end + end + + context 'using PostgreSQL', :postgresql do + context 'when replication lag is too great' do + it 'returns false' do + allow(Postgresql::ReplicationSlot) + .to receive(:lag_too_great?) + .and_return(true) + + expect(worker.healthy_database?).to eq(false) + end + end + + context 'when replication lag is small enough' do + it 'returns true' do + allow(Postgresql::ReplicationSlot) + .to receive(:lag_too_great?) + .and_return(false) + + expect(worker.healthy_database?).to eq(true) + end + end + end end end |