Commit f5b52633 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Detect SystemExit in tests and convert it to an error

Because if we let it fall through, it'll stop the tests early.
Make sure it's handled.
parent 0bfca6b5
......@@ -179,7 +179,7 @@ namespace :gitlab do
task reindex: :environment do
unless Gitlab::Database::Reindexing.enabled?
puts "This feature (database_reindexing) is currently disabled.".color(:yellow)
next
exit
end
Gitlab::Database::Reindexing.invoke
......@@ -193,7 +193,7 @@ namespace :gitlab do
task database_name => :environment do
unless Gitlab::Database::Reindexing.enabled?
puts "This feature (database_reindexing) is currently disabled.".color(:yellow)
next
exit
end
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
expect(Gitlab::Database::Reindexing).to receive(:enabled?).and_return(false)
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
......@@ -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).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
......
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