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

Define baseline for test for pipelines serializer

parent 0a4b853f
FactoryGirl.define do
factory :ci_trigger_without_token, class: Ci::Trigger do
factory :ci_trigger do
token 'token'
sequence(:token) { |n| "token#{n}" }
end
end
end
......@@ -93,6 +93,35 @@ describe PipelineSerializer do
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
describe '#represent_status' do
......
module ActiveRecord
class QueryRecorder
attr_reader :log
attr_reader :log, :cached
def initialize(&block)
@log = []
@cached = []
ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block)
end
def callback(name, start, finish, message_id, values)
return if %w(CACHE SCHEMA).include?(values[:name])
@log << values[:sql]
if values[:name]&.include?("CACHE")
@cached << values[:sql]
elsif !values[:name]&.include?("SCHEMA")
@log << values[:sql]
end
end
def count
@log.count
end
def cached_count
@cached.count
end
def log_message
@log.join("\n\n")
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