Commit 1ff48797 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'stub-rake-exit-in-tests' into 'master'

Detect SystemExit in tests and convert it to an error

See merge request gitlab-org/gitlab!77987
parents 83cc2c5f f5b52633
...@@ -179,7 +179,7 @@ namespace :gitlab do ...@@ -179,7 +179,7 @@ namespace :gitlab do
task reindex: :environment do task reindex: :environment do
unless Gitlab::Database::Reindexing.enabled? unless Gitlab::Database::Reindexing.enabled?
puts "This feature (database_reindexing) is currently disabled.".color(:yellow) puts "This feature (database_reindexing) is currently disabled.".color(:yellow)
next exit
end end
Gitlab::Database::Reindexing.invoke Gitlab::Database::Reindexing.invoke
...@@ -193,7 +193,7 @@ namespace :gitlab do ...@@ -193,7 +193,7 @@ namespace :gitlab do
task database_name => :environment do task database_name => :environment do
unless Gitlab::Database::Reindexing.enabled? unless Gitlab::Database::Reindexing.enabled?
puts "This feature (database_reindexing) is currently disabled.".color(:yellow) puts "This feature (database_reindexing) is currently disabled.".color(:yellow)
next exit
end end
Gitlab::Database::Reindexing.invoke(database_name) Gitlab::Database::Reindexing.invoke(database_name)
......
# frozen_string_literal: true
SystemExitDetected = Class.new(RuntimeError)
RSpec.configure do |config|
config.around do |example|
example.run
rescue SystemExit
# In any cases, we cannot raise SystemExit in the tests,
# because it'll skip any following tests from running.
# Convert it to something that won't skip everything.
# See https://gitlab.com/gitlab-org/gitlab/-/issues/350060
raise SystemExitDetected, "SystemExit should be rescued in the tests!"
end
end
...@@ -214,7 +214,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do ...@@ -214,7 +214,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
expect(Gitlab::Database::Reindexing).to receive(:enabled?).and_return(false) expect(Gitlab::Database::Reindexing).to receive(:enabled?).and_return(false)
expect(Gitlab::Database::Reindexing).not_to receive(:invoke) expect(Gitlab::Database::Reindexing).not_to receive(:invoke)
run_rake_task('gitlab:db:reindex') expect { run_rake_task('gitlab:db:reindex') }.to raise_error(SystemExit)
end end
end end
end end
...@@ -233,7 +233,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do ...@@ -233,7 +233,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
expect(Gitlab::Database::Reindexing).to receive(:enabled?).and_return(false) expect(Gitlab::Database::Reindexing).to receive(:enabled?).and_return(false)
expect(Gitlab::Database::Reindexing).not_to receive(:invoke).with(database_name) expect(Gitlab::Database::Reindexing).not_to receive(:invoke).with(database_name)
run_rake_task("gitlab:db:reindex:#{database_name}") expect { run_rake_task("gitlab:db:reindex:#{database_name}") }.to raise_error(SystemExit)
end end
end end
end end
......
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