2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::QueryLimiting::ActiveSupportSubscriber do
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:transaction) { instance_double(Gitlab::QueryLimiting::Transaction, increment: true) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Gitlab::QueryLimiting::Transaction)
|
|
|
|
.to receive(:current)
|
|
|
|
.and_return(transaction)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe '#sql' do
|
|
|
|
it 'increments the number of executed SQL queries' do
|
2018-03-27 19:54:05 +05:30
|
|
|
User.count
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(transaction)
|
2018-03-27 19:54:05 +05:30
|
|
|
.to have_received(:increment)
|
|
|
|
.once
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when the query is actually a rails cache hit' do
|
|
|
|
it 'does not increment the number of executed SQL queries' do
|
|
|
|
ActiveRecord::Base.connection.cache do
|
|
|
|
User.count
|
|
|
|
User.count
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(transaction)
|
|
|
|
.to have_received(:increment)
|
|
|
|
.once
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|