debian-mirror-gitlab/spec/tasks/gitlab/db/lock_writes_rake_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
3.5 KiB
Ruby
Raw Normal View History

2022-07-23 23:45:48 +05:30
# frozen_string_literal: true
require 'rake_helper'
2023-06-20 00:43:36 +05:30
RSpec.describe 'gitlab:db:lock_writes', :reestablished_active_record_base, feature_category: :cell do
2022-07-23 23:45:48 +05:30
before :all do
Rake.application.rake_require 'active_record/railties/databases'
Rake.application.rake_require 'tasks/seed_fu'
Rake.application.rake_require 'tasks/gitlab/db/validate_config'
Rake.application.rake_require 'tasks/gitlab/db/lock_writes'
# empty task as env is already loaded
Rake::Task.define_task :environment
end
2023-04-23 21:23:45 +05:30
let(:table_locker) { instance_double(Gitlab::Database::TablesLocker) }
let(:logger) { instance_double(Logger, level: nil) }
let(:dry_run) { false }
let(:verbose) { false }
2023-03-04 22:38:38 +05:30
before do
2023-04-23 21:23:45 +05:30
allow(Logger).to receive(:new).with($stdout).and_return(logger)
allow(Gitlab::Database::TablesLocker).to receive(:new).with(
logger: logger, dry_run: dry_run
).and_return(table_locker)
2023-03-17 16:20:25 +05:30
end
2023-04-23 21:23:45 +05:30
shared_examples "call table locker" do |method|
let(:log_level) { verbose ? Logger::INFO : Logger::WARN }
2023-03-04 22:38:38 +05:30
2023-04-23 21:23:45 +05:30
it "creates TablesLocker with dry run set and calls #{method}" do
expect(logger).to receive(:level=).with(log_level)
expect(table_locker).to receive(method)
2023-03-17 16:20:25 +05:30
2023-04-23 21:23:45 +05:30
run_rake_task("gitlab:db:#{method}")
2023-03-17 16:20:25 +05:30
end
2023-03-04 22:38:38 +05:30
end
2023-04-23 21:23:45 +05:30
describe 'lock_writes' do
context 'when environment sets DRY_RUN to true' do
let(:dry_run) { true }
2022-07-23 23:45:48 +05:30
2023-04-23 21:23:45 +05:30
before do
stub_env('DRY_RUN', 'true')
2022-07-23 23:45:48 +05:30
end
2023-04-23 21:23:45 +05:30
include_examples "call table locker", :lock_writes
2022-07-23 23:45:48 +05:30
end
2023-04-23 21:23:45 +05:30
context 'when environment sets DRY_RUN to false' do
let(:dry_run) { false }
2023-03-04 22:38:38 +05:30
2023-04-23 21:23:45 +05:30
before do
stub_env('DRY_RUN', 'false')
2023-03-04 22:38:38 +05:30
end
2023-04-23 21:23:45 +05:30
include_examples "call table locker", :lock_writes
2022-07-23 23:45:48 +05:30
end
2023-04-23 21:23:45 +05:30
context 'when environment does not define DRY_RUN' do
let(:dry_run) { false }
2022-07-23 23:45:48 +05:30
2023-04-23 21:23:45 +05:30
include_examples "call table locker", :lock_writes
end
2022-07-23 23:45:48 +05:30
2023-04-23 21:23:45 +05:30
context 'when environment sets VERBOSE to true' do
let(:verbose) { true }
2022-07-23 23:45:48 +05:30
2023-04-23 21:23:45 +05:30
before do
stub_env('VERBOSE', 'true')
2022-07-23 23:45:48 +05:30
end
2023-04-23 21:23:45 +05:30
include_examples "call table locker", :lock_writes
end
context 'when environment sets VERBOSE to false' do
let(:verbose) { false }
2023-03-04 22:38:38 +05:30
2023-04-23 21:23:45 +05:30
before do
stub_env('VERBOSE', 'false')
2023-03-04 22:38:38 +05:30
end
2023-04-23 21:23:45 +05:30
include_examples "call table locker", :lock_writes
2022-08-27 11:52:29 +05:30
end
2022-07-23 23:45:48 +05:30
2023-04-23 21:23:45 +05:30
context 'when environment does not define VERBOSE' do
include_examples "call table locker", :lock_writes
end
end
describe 'unlock_writes' do
context 'when environment sets DRY_RUN to true' do
let(:dry_run) { true }
2022-11-25 23:54:43 +05:30
before do
stub_env('DRY_RUN', 'true')
end
2023-04-23 21:23:45 +05:30
include_examples "call table locker", :unlock_writes
2022-11-25 23:54:43 +05:30
end
2023-04-23 21:23:45 +05:30
context 'when environment sets DRY_RUN to false' do
2022-08-27 11:52:29 +05:30
before do
2023-04-23 21:23:45 +05:30
stub_env('DRY_RUN', 'false')
2022-07-23 23:45:48 +05:30
end
2023-04-23 21:23:45 +05:30
include_examples "call table locker", :unlock_writes
end
2022-07-23 23:45:48 +05:30
2023-04-23 21:23:45 +05:30
context 'when environment does not define DRY_RUN' do
include_examples "call table locker", :unlock_writes
2022-07-23 23:45:48 +05:30
end
2023-04-23 21:23:45 +05:30
context 'when environment sets VERBOSE to true' do
let(:verbose) { true }
2022-07-23 23:45:48 +05:30
before do
2023-04-23 21:23:45 +05:30
stub_env('VERBOSE', 'true')
2022-07-23 23:45:48 +05:30
end
2023-04-23 21:23:45 +05:30
include_examples "call table locker", :lock_writes
end
2023-03-04 22:38:38 +05:30
2023-04-23 21:23:45 +05:30
context 'when environment sets VERBOSE to false' do
let(:verbose) { false }
2023-03-04 22:38:38 +05:30
2023-04-23 21:23:45 +05:30
before do
stub_env('VERBOSE', 'false')
2023-03-04 22:38:38 +05:30
end
2023-04-23 21:23:45 +05:30
include_examples "call table locker", :lock_writes
2022-07-23 23:45:48 +05:30
end
2023-04-23 21:23:45 +05:30
context 'when environment does not define VERBOSE' do
include_examples "call table locker", :lock_writes
end
2022-07-23 23:45:48 +05:30
end
end