Commit 8dbb228b authored by Pawel Chojnacki's avatar Pawel Chojnacki

Rails cache spec

parent 39ac6acb
require 'spec_helper'
describe Gitlab::Metrics::Subscribers::RailsCache do
let(:transaction) { Gitlab::Metrics::Transaction.new }
let(:env) { {} }
let(:transaction) { Gitlab::Metrics::Transaction.new(env) }
let(:subscriber) { described_class.new }
let(:event) { double(:event, duration: 15.2) }
describe '#cache_read' do
it 'increments the cache_read duration' do
expect(subscriber).to receive(:increment)
.with(:cache_read, event.duration)
expect(subscriber).to receive(:observe)
.with(:read, event.duration)
subscriber.cache_read(event)
end
......@@ -25,7 +26,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
it 'increments the cache_read_hit count' do
expect(transaction).to receive(:increment)
.with(:cache_read_hit_count, 1)
.with(:cache_read_hit_count, 1, false)
expect(transaction).to receive(:increment)
.with(any_args).at_least(1) # Other calls
......@@ -49,7 +50,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
it 'increments the cache_read_miss count' do
expect(transaction).to receive(:increment)
.with(:cache_read_miss_count, 1)
.with(:cache_read_miss_count, 1, false)
expect(transaction).to receive(:increment)
.with(any_args).at_least(1) # Other calls
......@@ -72,8 +73,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
describe '#cache_write' do
it 'increments the cache_write duration' do
expect(subscriber).to receive(:increment)
.with(:cache_write, event.duration)
expect(subscriber).to receive(:observe)
.with(:write, event.duration)
subscriber.cache_write(event)
end
......@@ -81,8 +82,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
describe '#cache_delete' do
it 'increments the cache_delete duration' do
expect(subscriber).to receive(:increment)
.with(:cache_delete, event.duration)
expect(subscriber).to receive(:observe)
.with(:delete, event.duration)
subscriber.cache_delete(event)
end
......@@ -90,8 +91,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
describe '#cache_exist?' do
it 'increments the cache_exists duration' do
expect(subscriber).to receive(:increment)
.with(:cache_exists, event.duration)
expect(subscriber).to receive(:observe)
.with(:exists, event.duration)
subscriber.cache_exist?(event)
end
......@@ -145,12 +146,12 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
end
end
describe '#increment' do
describe '#observe' do
context 'without a transaction' do
it 'returns' do
expect(transaction).not_to receive(:increment)
subscriber.increment(:foo, 15.2)
subscriber.observe(:foo, 15.2)
end
end
......@@ -162,18 +163,18 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
it 'increments the total and specific cache duration' do
expect(transaction).to receive(:increment)
.with(:cache_duration, event.duration)
.with(:cache_duration, event.duration, false)
expect(transaction).to receive(:increment)
.with(:cache_count, 1)
.with(:cache_count, 1, false)
expect(transaction).to receive(:increment)
.with(:cache_delete_duration, event.duration)
.with(:cache_delete_duration, event.duration, false)
expect(transaction).to receive(:increment)
.with(:cache_delete_count, 1)
.with(:cache_delete_count, 1, false)
subscriber.increment(:cache_delete, event.duration)
subscriber.observe(:delete, event.duration)
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