diff options
Diffstat (limited to 'spec/lib/gitlab/memory/watchdog/monitor/rss_memory_limit_spec.rb')
-rw-r--r-- | spec/lib/gitlab/memory/watchdog/monitor/rss_memory_limit_spec.rb | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/spec/lib/gitlab/memory/watchdog/monitor/rss_memory_limit_spec.rb b/spec/lib/gitlab/memory/watchdog/monitor/rss_memory_limit_spec.rb index 9e25cfda782..4780b1eba53 100644 --- a/spec/lib/gitlab/memory/watchdog/monitor/rss_memory_limit_spec.rb +++ b/spec/lib/gitlab/memory/watchdog/monitor/rss_memory_limit_spec.rb @@ -4,25 +4,38 @@ 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 } + let(:max_rss_limit_gauge) { instance_double(::Prometheus::Client::Gauge) } + let(:memory_limit_bytes) { 2_097_152_000 } + let(:worker_memory_bytes) { 1_048_576_000 } subject(:monitor) do - described_class.new(memory_limit: memory_limit) + described_class.new(memory_limit_bytes: memory_limit_bytes) end before do - allow(Gitlab::Metrics::System).to receive(:memory_usage_rss).and_return({ total: worker_memory }) + allow(Gitlab::Metrics).to receive(:gauge) + .with(:gitlab_memwd_max_memory_limit, anything) + .and_return(max_rss_limit_gauge) + allow(max_rss_limit_gauge).to receive(:set) + allow(Gitlab::Metrics::System).to receive(:memory_usage_rss).and_return({ total: worker_memory_bytes }) + end + + describe '#initialize' do + it 'sets the max rss limit gauge' do + expect(max_rss_limit_gauge).to receive(:set).with({}, memory_limit_bytes) + + monitor + end end describe '#call' do context 'when process exceeds threshold' do - let(:worker_memory) { memory_limit + 1 } + let(:worker_memory_bytes) { memory_limit_bytes + 1 } let(:payload) do { message: 'rss memory limit exceeded', - memwd_rss_bytes: worker_memory, - memwd_max_rss_bytes: memory_limit + memwd_rss_bytes: worker_memory_bytes, + memwd_max_rss_bytes: memory_limit_bytes } end @@ -30,7 +43,7 @@ RSpec.describe Gitlab::Memory::Watchdog::Monitor::RssMemoryLimit do end context 'when process does not exceed threshold' do - let(:worker_memory) { memory_limit - 1 } + let(:worker_memory_bytes) { memory_limit_bytes - 1 } let(:payload) { {} } include_examples 'returns Watchdog Monitor result', threshold_violated: false |