summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/memory/reports/jemalloc_stats_spec.rb
blob: ce06c270a0580165371dedf818992fa03db8c297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Memory::Reports::JemallocStats do
  subject(:jemalloc_stats) { described_class.new }

  let(:writer) { StringIO.new }

  describe '.run' do
    context 'when :report_jemalloc_stats ops FF is enabled' do
      it 'dumps jemalloc stats to the given writer' do
        expect(Gitlab::Memory::Jemalloc).to receive(:dump_stats).with(writer)

        jemalloc_stats.run(writer)
      end
    end

    context 'when :report_jemalloc_stats ops FF is disabled' do
      before do
        stub_feature_flags(report_jemalloc_stats: false)
      end

      it 'does not run the report' do
        expect(Gitlab::Memory::Jemalloc).not_to receive(:dump_stats)

        jemalloc_stats.run(writer)
      end
    end
  end

  describe '.active?' do
    subject(:active) { jemalloc_stats.active? }

    context 'when :report_jemalloc_stats ops FF is enabled' do
      it { is_expected.to be true }
    end

    context 'when :report_jemalloc_stats ops FF is disabled' do
      before do
        stub_feature_flags(report_jemalloc_stats: false)
      end

      it { is_expected.to be false }
    end
  end
end