2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'Request Profiler' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
shared_examples 'profiling a request' do
|
|
|
|
before do
|
|
|
|
allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache::MemoryStore.new)
|
|
|
|
allow(RubyProf::Profile).to receive(:profile) do |&blk|
|
|
|
|
blk.call
|
|
|
|
RubyProf::Profile.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a profile of the request' do
|
|
|
|
project = create(:project, namespace: user.namespace)
|
|
|
|
time = Time.now
|
2017-09-10 17:25:29 +05:30
|
|
|
path = "/#{project.full_path}"
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
Timecop.freeze(time) do
|
2019-02-13 22:33:31 +05:30
|
|
|
get path, params: {}, headers: { 'X-Profile-Token' => Gitlab::RequestProfiler.profile_token }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
profile_path = "#{Gitlab.config.shared.path}/tmp/requests_profiles/#{path.tr('/', '|')}_#{time.to_i}.html"
|
|
|
|
expect(File.exist?(profile_path)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Gitlab::RequestProfiler.remove_all_profiles
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is logged-in" do
|
|
|
|
before do
|
|
|
|
login_as(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'profiling a request'
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is not logged-in" do
|
|
|
|
include_examples 'profiling a request'
|
|
|
|
end
|
|
|
|
end
|