diff options
author | Ahmad Sherif <me@ahmadsherif.com> | 2017-05-01 00:29:34 +0200 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2017-05-01 17:32:45 +0200 |
commit | 13de8aeec8cce390b07c0ab31d5336cb54123ec7 (patch) | |
tree | 466f49788552391b23bd8561452913230ed74ba8 /spec/requests/request_profiler_spec.rb | |
parent | 03f13af588cf2b578a27717db492c216fcafbf9a (diff) | |
download | gitlab-ce-13de8aeec8cce390b07c0ab31d5336cb54123ec7.tar.gz |
Add specs for Gitlab::RequestProfiler
Closes #31513
Diffstat (limited to 'spec/requests/request_profiler_spec.rb')
-rw-r--r-- | spec/requests/request_profiler_spec.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/requests/request_profiler_spec.rb b/spec/requests/request_profiler_spec.rb new file mode 100644 index 00000000000..51fbfecec4b --- /dev/null +++ b/spec/requests/request_profiler_spec.rb @@ -0,0 +1,44 @@ +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 + path = "/#{project.path_with_namespace}" + + Timecop.freeze(time) do + get path, nil, 'X-Profile-Token' => Gitlab::RequestProfiler.profile_token + 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 |