diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-14 06:12:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-14 06:12:37 +0300 |
commit | 1a92cb5aaf5a1bc1338a5124275c35b18d295255 (patch) | |
tree | 6c93f80589c59fd20aad0664877c5cc1372a5c9f /spec/lib/gitlab | |
parent | 3521fa595b022a402f3ed1e8c423021e6ad8ae49 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/memory/jemalloc_spec.rb | 11 | ||||
-rw-r--r-- | spec/lib/gitlab/memory/reports/jemalloc_stats_spec.rb | 23 |
2 files changed, 20 insertions, 14 deletions
diff --git a/spec/lib/gitlab/memory/jemalloc_spec.rb b/spec/lib/gitlab/memory/jemalloc_spec.rb index a6272a020ca..414d6017534 100644 --- a/spec/lib/gitlab/memory/jemalloc_spec.rb +++ b/spec/lib/gitlab/memory/jemalloc_spec.rb @@ -5,9 +5,11 @@ require 'tmpdir' RSpec.describe Gitlab::Memory::Jemalloc do let(:outdir) { Dir.mktmpdir } + let(:tmp_outdir) { Dir.mktmpdir } after do FileUtils.rm_f(outdir) + FileUtils.rm_f(tmp_outdir) end context 'when jemalloc is loaded' do @@ -29,7 +31,7 @@ RSpec.describe Gitlab::Memory::Jemalloc do describe '.dump_stats' do it 'writes stats JSON file' do - file_path = described_class.dump_stats(path: outdir, format: format) + file_path = described_class.dump_stats(path: outdir, tmp_dir: tmp_outdir, format: format) file = Dir.entries(outdir).find { |e| e.match(/jemalloc_stats\.#{$$}\.\d+\.json$/) } expect(file).not_to be_nil @@ -56,7 +58,8 @@ RSpec.describe Gitlab::Memory::Jemalloc do describe '.dump_stats' do shared_examples 'writes stats text file' do |filename_label, filename_pattern| it do - described_class.dump_stats(path: outdir, format: format, filename_label: filename_label) + described_class.dump_stats( + path: outdir, tmp_dir: tmp_outdir, format: format, filename_label: filename_label) file = Dir.entries(outdir).find { |e| e.match(filename_pattern) } expect(file).not_to be_nil @@ -88,7 +91,7 @@ RSpec.describe Gitlab::Memory::Jemalloc do describe '.dump_stats' do it 'raises an error' do expect do - described_class.dump_stats(path: outdir, format: format) + described_class.dump_stats(path: outdir, tmp_dir: tmp_outdir, format: format) end.to raise_error(/format must be one of/) end end @@ -110,7 +113,7 @@ RSpec.describe Gitlab::Memory::Jemalloc do it 'does nothing' do stub_env('LD_PRELOAD', nil) - described_class.dump_stats(path: outdir) + described_class.dump_stats(path: outdir, tmp_dir: tmp_outdir) expect(Dir.empty?(outdir)).to be(true) end diff --git a/spec/lib/gitlab/memory/reports/jemalloc_stats_spec.rb b/spec/lib/gitlab/memory/reports/jemalloc_stats_spec.rb index 53fae48776b..b327a40bc2c 100644 --- a/spec/lib/gitlab/memory/reports/jemalloc_stats_spec.rb +++ b/spec/lib/gitlab/memory/reports/jemalloc_stats_spec.rb @@ -3,14 +3,19 @@ require 'spec_helper' RSpec.describe Gitlab::Memory::Reports::JemallocStats do - let(:reports_dir) { '/empty-dir' } - let(:jemalloc_stats) { described_class.new(reports_path: reports_dir) } + let_it_be(:outdir) { Dir.mktmpdir } + + let(:jemalloc_stats) { described_class.new(reports_path: outdir) } + + after do + FileUtils.rm_f(outdir) + end describe '.run' do context 'when :report_jemalloc_stats ops FF is enabled' do let(:worker_id) { 'puma_1' } let(:report_name) { 'report.json' } - let(:report_path) { File.join(reports_dir, report_name) } + let(:report_path) { File.join(outdir, report_name) } before do allow(Prometheus::PidProvider).to receive(:worker_id).and_return(worker_id) @@ -18,14 +23,16 @@ RSpec.describe Gitlab::Memory::Reports::JemallocStats do it 'invokes Jemalloc.dump_stats and returns file path' do expect(Gitlab::Memory::Jemalloc) - .to receive(:dump_stats).with(path: reports_dir, filename_label: worker_id).and_return(report_path) + .to receive(:dump_stats) + .with(path: outdir, + tmp_dir: File.join(outdir, '/tmp'), + filename_label: worker_id) + .and_return(report_path) expect(jemalloc_stats.run).to eq(report_path) end describe 'reports cleanup' do - let_it_be(:outdir) { Dir.mktmpdir } - let(:jemalloc_stats) { described_class.new(reports_path: outdir) } before do @@ -33,10 +40,6 @@ RSpec.describe Gitlab::Memory::Reports::JemallocStats do allow(Gitlab::Memory::Jemalloc).to receive(:dump_stats) end - after do - FileUtils.rm_f(outdir) - end - context 'when number of reports exceeds `max_reports_stored`' do let_it_be(:reports) do now = Time.current |