debian-mirror-gitlab/spec/initializers/diagnostic_reports_spec.rb

74 lines
2.1 KiB
Ruby
Raw Normal View History

2022-08-27 11:52:29 +05:30
# 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
2022-11-25 23:54:43 +05:30
context 'when run in Puma context' do
2022-08-27 11:52:29 +05:30
before do
2022-11-25 23:54:43 +05:30
allow(::Gitlab::Runtime).to receive(:puma?).and_return(true)
2022-08-27 11:52:29 +05:30
end
2022-11-25 23:54:43 +05:30
let(:report_daemon) { instance_double(Gitlab::Memory::ReportsDaemon) }
2022-08-27 11:52:29 +05:30
2022-11-25 23:54:43 +05:30
it 'modifies worker startup hooks, starts Gitlab::Memory::ReportsDaemon' do
2022-08-27 11:52:29 +05:30
expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_start).and_call_original
2022-11-25 23:54:43 +05:30
expect_next_instance_of(Gitlab::Memory::ReportsDaemon) do |daemon|
expect(daemon).to receive(:start).and_call_original
# make sleep no-op
allow(daemon).to receive(:sleep).and_return(nil)
# let alive return 3 times: true, true, false
allow(daemon).to receive(:alive).and_return(true, true, false)
end
2022-08-27 11:52:29 +05:30
load_initializer
end
end
2022-11-25 23:54:43 +05:30
context 'when run in non-Puma context, such as rails console, tests, Sidekiq' do
2022-08-27 11:52:29 +05:30
before do
2022-11-25 23:54:43 +05:30
allow(::Gitlab::Runtime).to receive(:puma?).and_return(false)
2022-08-27 11:52:29 +05:30
end
include_examples 'does not modify worker startup hooks'
end
end
context 'when GITLAB_DIAGNOSTIC_REPORTS_ENABLED is not set' do
before do
2022-11-25 23:54:43 +05:30
allow(::Gitlab::Runtime).to receive(:puma?).and_return(true)
2022-08-27 11:52:29 +05:30
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)
2022-11-25 23:54:43 +05:30
allow(::Gitlab::Runtime).to receive(:puma?).and_return(true)
2022-08-27 11:52:29 +05:30
end
include_examples 'does not modify worker startup hooks'
end
end