Commit 062806e4 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Define baseline for test for pipelines serializer

parent 0a4b853f
FactoryGirl.define do FactoryGirl.define do
factory :ci_trigger_without_token, class: Ci::Trigger do factory :ci_trigger_without_token, class: Ci::Trigger do
factory :ci_trigger do factory :ci_trigger do
token 'token' sequence(:token) { |n| "token#{n}" }
end end
end end
end end
...@@ -93,6 +93,35 @@ describe PipelineSerializer do ...@@ -93,6 +93,35 @@ describe PipelineSerializer do
end end
end end
end end
context 'number of queries' do
let(:resource) { Ci::Pipeline.all }
before do
Ci::Pipeline::AVAILABLE_STATUSES.each do |status|
create_pipeline(status)
end
end
it "verifies number of queries" do
recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.count).to be_within(320).of(10)
end
def create_pipeline(status)
create(:ci_empty_pipeline, status: status).tap do |pipeline|
Ci::Build::AVAILABLE_STATUSES.each do |status|
create_build(pipeline, status, status)
end
end
end
def create_build(pipeline, stage, status)
create(:ci_build, :tags, :triggered, :artifacts,
pipeline: pipeline, stage: stage,
name: stage, status: status)
end
end
end end
describe '#represent_status' do describe '#represent_status' do
......
module ActiveRecord module ActiveRecord
class QueryRecorder class QueryRecorder
attr_reader :log attr_reader :log, :cached
def initialize(&block) def initialize(&block)
@log = [] @log = []
@cached = []
ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block) ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block)
end end
def callback(name, start, finish, message_id, values) def callback(name, start, finish, message_id, values)
return if %w(CACHE SCHEMA).include?(values[:name]) if values[:name]&.include?("CACHE")
@cached << values[:sql]
elsif !values[:name]&.include?("SCHEMA")
@log << values[:sql] @log << values[:sql]
end end
end
def count def count
@log.count @log.count
end end
def cached_count
@cached.count
end
def log_message def log_message
@log.join("\n\n") @log.join("\n\n")
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