diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /spec/initializers/diagnostic_reports_spec.rb | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'spec/initializers/diagnostic_reports_spec.rb')
-rw-r--r-- | spec/initializers/diagnostic_reports_spec.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/initializers/diagnostic_reports_spec.rb b/spec/initializers/diagnostic_reports_spec.rb new file mode 100644 index 00000000000..70574194916 --- /dev/null +++ b/spec/initializers/diagnostic_reports_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'diagnostic reports' do + subject(:load_initializer) do + load Rails.root.join('config/initializers/diagnostic_reports.rb') + end + + shared_examples 'does not modify worker startup hooks' do + it do + expect(Gitlab::Cluster::LifecycleEvents).not_to receive(:on_worker_start) + expect(Gitlab::Memory::ReportsDaemon).not_to receive(:instance) + + load_initializer + end + end + + context 'when GITLAB_DIAGNOSTIC_REPORTS_ENABLED is set to true' do + before do + stub_env('GITLAB_DIAGNOSTIC_REPORTS_ENABLED', true) + end + + context 'when run in application context' do + before do + allow(::Gitlab::Runtime).to receive(:application?).and_return(true) + end + + it 'modifies worker startup hooks' do + report_daemon = instance_double(Gitlab::Memory::ReportsDaemon) + + expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_start).and_call_original + expect(Gitlab::Memory::ReportsDaemon).to receive(:instance).and_return(report_daemon) + expect(report_daemon).to receive(:start) + + load_initializer + end + end + + context 'when run in non-application context, such as rails console or tests' do + before do + allow(::Gitlab::Runtime).to receive(:application?).and_return(false) + end + + include_examples 'does not modify worker startup hooks' + end + end + + context 'when GITLAB_DIAGNOSTIC_REPORTS_ENABLED is not set' do + before do + allow(::Gitlab::Runtime).to receive(:application?).and_return(true) + end + + include_examples 'does not modify worker startup hooks' + end + + context 'when GITLAB_DIAGNOSTIC_REPORTS_ENABLED is set to false' do + before do + stub_env('GITLAB_DIAGNOSTIC_REPORTS_ENABLED', false) + allow(::Gitlab::Runtime).to receive(:application?).and_return(true) + end + + include_examples 'does not modify worker startup hooks' + end +end |