diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-29 21:09:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-29 21:09:26 +0300 |
commit | 7fe1490a589010205896293ec225dfcc88676a9e (patch) | |
tree | 565f6771a34ef557a6dcdd37f46f379e904f0a45 /spec/initializers/diagnostic_reports_spec.rb | |
parent | a466e9450d5949aa762913729918db02b5d27761 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/initializers/diagnostic_reports_spec.rb')
-rw-r--r-- | spec/initializers/diagnostic_reports_spec.rb | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/spec/initializers/diagnostic_reports_spec.rb b/spec/initializers/diagnostic_reports_spec.rb index 2022076072b..20d0b2714f0 100644 --- a/spec/initializers/diagnostic_reports_spec.rb +++ b/spec/initializers/diagnostic_reports_spec.rb @@ -28,10 +28,10 @@ RSpec.describe 'diagnostic reports' do end let(:report_daemon) { instance_double(Gitlab::Memory::ReportsDaemon) } + let(:reporter) { instance_double(Gitlab::Memory::Reporter) } it 'modifies worker startup hooks, starts Gitlab::Memory::ReportsDaemon' do expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_start).and_call_original - expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_stop) expect_next_instance_of(Gitlab::Memory::ReportsDaemon) do |daemon| expect(daemon).to receive(:start) end @@ -39,14 +39,30 @@ RSpec.describe 'diagnostic reports' do load_initializer end - it 'writes scheduled heap dumps in on_worker_stop' do - expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_start) - expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_stop).and_call_original - expect(Gitlab::Memory::Reports::HeapDump).to receive(:write_conditionally) + context 'when GITLAB_MEMWD_DUMP_HEAP is set' do + before do + stub_env('GITLAB_MEMWD_DUMP_HEAP', '1') + end - load_initializer - # This is necessary because this hook normally fires during worker shutdown. - Gitlab::Cluster::LifecycleEvents.do_worker_stop + it 'writes scheduled heap dumps in on_worker_stop' do + expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_start) + expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_stop).and_call_original + expect(Gitlab::Memory::Reporter).to receive(:new).and_return(reporter) + expect(reporter).to receive(:run_report).with(an_instance_of(Gitlab::Memory::Reports::HeapDump)) + + load_initializer + # This is necessary because this hook normally fires during worker shutdown. + Gitlab::Cluster::LifecycleEvents.do_worker_stop + end + end + + context 'when GITLAB_MEMWD_DUMP_HEAP is not set' do + it 'does not write heap dumps' do + expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_start) + expect(Gitlab::Cluster::LifecycleEvents).not_to receive(:on_worker_stop) + + load_initializer + end end end |