2017-04-30 18:29:34 -04:00
|
|
|
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
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, namespace: user.namespace)
|
2017-04-30 18:29:34 -04:00
|
|
|
time = Time.now
|
2017-07-21 20:37:22 -04:00
|
|
|
path = "/#{project.full_path}"
|
2017-04-30 18:29:34 -04:00
|
|
|
|
|
|
|
Timecop.freeze(time) do
|
2019-01-16 07:09:29 -05:00
|
|
|
get path, params: {}, headers: { 'X-Profile-Token' => Gitlab::RequestProfiler.profile_token }
|
2017-04-30 18:29:34 -04:00
|
|
|
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
|