2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::UsageDataCounters::RedisCounter, :clean_gitlab_redis_shared_state do
|
2019-10-12 21:52:04 +05:30
|
|
|
let(:redis_key) { 'foobar' }
|
|
|
|
|
|
|
|
subject { Class.new.extend(described_class) }
|
|
|
|
|
|
|
|
before do
|
2021-10-27 15:23:28 +05:30
|
|
|
allow(::ServicePing::ServicePingSettings).to receive(:enabled?).and_return(service_ping_enabled)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe '.increment' do
|
|
|
|
context 'when usage_ping is disabled' do
|
2021-10-27 15:23:28 +05:30
|
|
|
let(:service_ping_enabled) { false }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
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
|
2021-10-27 15:23:28 +05:30
|
|
|
let(:service_ping_enabled) { true }
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it 'counter is increased' do
|
|
|
|
expect do
|
|
|
|
subject.increment(redis_key)
|
|
|
|
end.to change { subject.total_count(redis_key) }.by(1)
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe '.increment_by' do
|
|
|
|
context 'when usage_ping is disabled' do
|
2021-10-27 15:23:28 +05:30
|
|
|
let(:service_ping_enabled) { false }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
it 'counter is not increased' do
|
|
|
|
expect do
|
|
|
|
subject.increment_by(redis_key, 3)
|
|
|
|
end.not_to change { subject.total_count(redis_key) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when usage_ping is enabled' do
|
2021-10-27 15:23:28 +05:30
|
|
|
let(:service_ping_enabled) { true }
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it 'counter is increased' do
|
|
|
|
expect do
|
|
|
|
subject.increment_by(redis_key, 3)
|
|
|
|
end.to change { subject.total_count(redis_key) }.by(3)
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|