Commit 75e60e42 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'fj-avoid-incresaing-usage-ping-when-not-enabled' into 'master'

Avoid increasing redis counters when usage_ping is disabled

See merge request gitlab-org/gitlab-ce!30949
parents 2db1317b 351bc078
---
title: Avoid increasing redis counters when usage_ping is disabled
merge_request: 30949
author:
type: changed
......@@ -4,6 +4,8 @@ module Gitlab
module UsageDataCounters
module RedisCounter
def increment(redis_counter_key)
return unless Gitlab::CurrentSettings.usage_ping_enabled
Gitlab::Redis::SharedState.with { |redis| redis.incr(redis_counter_key) }
end
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::UsageDataCounters::RedisCounter, :clean_gitlab_redis_shared_state do
let(:redis_key) { 'foobar' }
subject { Class.new.extend(described_class) }
before do
stub_application_setting(usage_ping_enabled: setting_value)
end
context 'when usage_ping is disabled' do
let(:setting_value) { false }
it 'counter is not increased' do
expect do
subject.increment(redis_key)
end.not_to change { subject.total_count(redis_key) }
end
end
context 'when usage_ping is enabled' do
let(:setting_value) { true }
it 'counter is increased' do
expect do
subject.increment(redis_key)
end.to change { subject.total_count(redis_key) }.by(1)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment