diff options
author | Paco Guzman <pacoguzmanp@gmail.com> | 2016-06-29 18:03:20 +0300 |
---|---|---|
committer | Paco Guzman <pacoguzmanp@gmail.com> | 2016-07-05 13:28:06 +0300 |
commit | 330de255b75fa7b9897844582b8fd7e020f4efa7 (patch) | |
tree | d8ec783d7b842e9d0523093553190b25349132f8 /spec/lib/gitlab/metrics | |
parent | e9a4d117f2fb6f10af3357a8a6591ba7022d9c62 (diff) |
RailsCache metrics now includes fetch_hit/fetch_miss and read_hit/read_miss info.
Diffstat (limited to 'spec/lib/gitlab/metrics')
-rw-r--r-- | spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb index d824dc54438..d986c6fac43 100644 --- a/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb @@ -13,6 +13,61 @@ describe Gitlab::Metrics::Subscribers::RailsCache do subscriber.cache_read(event) end + + context 'with a transaction' do + before do + allow(subscriber).to receive(:current_transaction). + and_return(transaction) + end + + context 'with hit event' do + let(:event) { double(:event, duration: 15.2, payload: { hit: true }) } + + it 'increments the cache_read_hit count' do + expect(transaction).to receive(:increment). + with(:cache_read_hit_count, 1) + expect(transaction).to receive(:increment). + with(any_args).at_least(1) # Other calls + + subscriber.cache_read(event) + end + + context 'when super operation is fetch' do + let(:event) { double(:event, duration: 15.2, payload: { hit: true, super_operation: :fetch }) } + + it 'does not increment cache read miss' do + expect(transaction).not_to receive(:increment). + with(:cache_read_hit_count, 1) + + subscriber.cache_read(event) + end + end + end + + context 'with miss event' do + let(:event) { double(:event, duration: 15.2, payload: { hit: false }) } + + it 'increments the cache_read_miss count' do + expect(transaction).to receive(:increment). + with(:cache_read_miss_count, 1) + expect(transaction).to receive(:increment). + with(any_args).at_least(1) # Other calls + + subscriber.cache_read(event) + end + + context 'when super operation is fetch' do + let(:event) { double(:event, duration: 15.2, payload: { hit: false, super_operation: :fetch }) } + + it 'does not increment cache read miss' do + expect(transaction).not_to receive(:increment). + with(:cache_read_miss_count, 1) + + subscriber.cache_read(event) + end + end + end + end end describe '#cache_write' do @@ -42,6 +97,54 @@ describe Gitlab::Metrics::Subscribers::RailsCache do end end + describe '#cache_fetch_hit' do + context 'without a transaction' do + it 'returns' do + expect(transaction).not_to receive(:increment) + + subscriber.cache_fetch_hit(event) + end + end + + context 'with a transaction' do + before do + allow(subscriber).to receive(:current_transaction). + and_return(transaction) + end + + it 'increments the cache_read_hit count' do + expect(transaction).to receive(:increment). + with(:cache_read_hit_count, 1) + + subscriber.cache_fetch_hit(event) + end + end + end + + describe '#cache_generate' do + context 'without a transaction' do + it 'returns' do + expect(transaction).not_to receive(:increment) + + subscriber.cache_generate(event) + end + end + + context 'with a transaction' do + before do + allow(subscriber).to receive(:current_transaction). + and_return(transaction) + end + + it 'increments the cache_fetch_miss count' do + expect(transaction).to receive(:increment). + with(:cache_read_miss_count, 1) + + subscriber.cache_generate(event) + end + end + end + describe '#increment' do context 'without a transaction' do it 'returns' do |