Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rss_memory_limit_spec.rb « monitor « watchdog « memory « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9e25cfda782e8646f0b84795650f99780b0d758c (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
# frozen_string_literal: true

require 'fast_spec_helper'
require 'support/shared_examples/lib/gitlab/memory/watchdog/monitor_result_shared_examples'

RSpec.describe Gitlab::Memory::Watchdog::Monitor::RssMemoryLimit do
  let(:memory_limit) { 2048 }
  let(:worker_memory) { 1024 }

  subject(:monitor) do
    described_class.new(memory_limit: memory_limit)
  end

  before do
    allow(Gitlab::Metrics::System).to receive(:memory_usage_rss).and_return({ total: worker_memory })
  end

  describe '#call' do
    context 'when process exceeds threshold' do
      let(:worker_memory) { memory_limit + 1 }
      let(:payload) do
        {
          message: 'rss memory limit exceeded',
          memwd_rss_bytes: worker_memory,
          memwd_max_rss_bytes: memory_limit
        }
      end

      include_examples 'returns Watchdog Monitor result', threshold_violated: true
    end

    context 'when process does not exceed threshold' do
      let(:worker_memory) { memory_limit - 1 }
      let(:payload) { {} }

      include_examples 'returns Watchdog Monitor result', threshold_violated: false
    end
  end
end