2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-30 18:29:34 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe 'Admin::RequestsProfilesController' do
|
2019-07-23 05:30:00 -04:00
|
|
|
let(:tmpdir) { Dir.mktmpdir('profiler-test') }
|
|
|
|
|
2017-04-30 18:29:34 -04:00
|
|
|
before do
|
2019-07-23 05:30:00 -04:00
|
|
|
stub_const('Gitlab::RequestProfiler::PROFILES_DIR', tmpdir)
|
2020-11-23 10:09:37 -05:00
|
|
|
admin = create(:admin)
|
|
|
|
sign_in(admin)
|
|
|
|
gitlab_enable_admin_mode_sign_in(admin)
|
2017-04-30 18:29:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2019-07-23 05:30:00 -04:00
|
|
|
FileUtils.rm_rf(tmpdir)
|
2017-04-30 18:29:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /admin/requests_profiles' do
|
|
|
|
it 'shows the current profile token' do
|
|
|
|
allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache::MemoryStore.new)
|
|
|
|
|
|
|
|
visit admin_requests_profiles_path
|
|
|
|
|
|
|
|
expect(page).to have_content("X-Profile-Token: #{Gitlab::RequestProfiler.profile_token}")
|
|
|
|
end
|
|
|
|
|
2019-06-27 09:42:14 -04:00
|
|
|
context 'when having multiple profiles' do
|
|
|
|
let(:time1) { 1.hour.ago }
|
|
|
|
let(:time2) { 2.hours.ago }
|
|
|
|
|
|
|
|
let(:profiles) do
|
|
|
|
[
|
|
|
|
{
|
2019-09-18 10:02:45 -04:00
|
|
|
request_path: '/gitlab-org/gitlab-foss',
|
|
|
|
name: "|gitlab-org|gitlab-foss_#{time1.to_i}_execution.html",
|
2019-06-27 09:42:14 -04:00
|
|
|
created: time1,
|
|
|
|
profile_mode: 'Execution'
|
|
|
|
},
|
|
|
|
{
|
2019-09-18 10:02:45 -04:00
|
|
|
request_path: '/gitlab-org/gitlab-foss',
|
|
|
|
name: "|gitlab-org|gitlab-foss_#{time2.to_i}_execution.html",
|
2019-06-27 09:42:14 -04:00
|
|
|
created: time2,
|
|
|
|
profile_mode: 'Execution'
|
|
|
|
},
|
|
|
|
{
|
2019-09-18 10:02:45 -04:00
|
|
|
request_path: '/gitlab-org/gitlab-foss',
|
|
|
|
name: "|gitlab-org|gitlab-foss_#{time1.to_i}_memory.html",
|
2019-06-27 09:42:14 -04:00
|
|
|
created: time1,
|
|
|
|
profile_mode: 'Memory'
|
|
|
|
},
|
|
|
|
{
|
2019-09-18 10:02:45 -04:00
|
|
|
request_path: '/gitlab-org/gitlab-foss',
|
|
|
|
name: "|gitlab-org|gitlab-foss_#{time2.to_i}_memory.html",
|
2019-06-27 09:42:14 -04:00
|
|
|
created: time2,
|
|
|
|
profile_mode: 'Memory'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
request_path: '/gitlab-org/infrastructure',
|
|
|
|
name: "|gitlab-org|infrastructure_#{time1.to_i}_execution.html",
|
|
|
|
created: time1,
|
|
|
|
profile_mode: 'Execution'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
request_path: '/gitlab-org/infrastructure',
|
|
|
|
name: "|gitlab-org|infrastructure_#{time2.to_i}_memory.html",
|
|
|
|
created: time2,
|
|
|
|
profile_mode: 'Memory'
|
2019-07-23 05:30:00 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
request_path: '/gitlab-org/infrastructure',
|
|
|
|
name: "|gitlab-org|infrastructure_#{time2.to_i}.html",
|
|
|
|
created: time2,
|
|
|
|
profile_mode: 'Unknown'
|
2019-06-27 09:42:14 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
2017-04-30 18:29:34 -04:00
|
|
|
|
2019-06-27 09:42:14 -04:00
|
|
|
before do
|
|
|
|
profiles.each do |profile|
|
|
|
|
FileUtils.touch(File.join(Gitlab::RequestProfiler::PROFILES_DIR, profile[:name]))
|
|
|
|
end
|
2017-04-30 18:29:34 -04:00
|
|
|
end
|
|
|
|
|
2019-06-27 09:42:14 -04:00
|
|
|
it 'lists all available profiles' do
|
|
|
|
visit admin_requests_profiles_path
|
|
|
|
|
|
|
|
profiles.each do |profile|
|
|
|
|
within('.card', text: profile[:request_path]) do
|
|
|
|
expect(page).to have_selector(
|
|
|
|
"a[href='#{admin_requests_profile_path(profile[:name])}']",
|
|
|
|
text: "#{profile[:created].to_s(:long)} #{profile[:profile_mode]}")
|
|
|
|
end
|
|
|
|
end
|
2017-04-30 18:29:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /admin/requests_profiles/:profile' do
|
|
|
|
context 'when a profile exists' do
|
2019-06-27 09:42:14 -04:00
|
|
|
before do
|
2017-04-30 18:29:34 -04:00
|
|
|
File.write("#{Gitlab::RequestProfiler::PROFILES_DIR}/#{profile}", content)
|
2019-06-27 09:42:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when is valid call stack profile' do
|
|
|
|
let(:content) { 'This is a call stack request profile' }
|
|
|
|
let(:profile) { "|gitlab-org|gitlab-ce_#{Time.now.to_i}_execution.html" }
|
|
|
|
|
|
|
|
it 'displays the content' do
|
|
|
|
visit admin_requests_profile_path(profile)
|
|
|
|
|
|
|
|
expect(page).to have_content(content)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when is valid memory profile' do
|
|
|
|
let(:content) { 'This is a memory request profile' }
|
|
|
|
let(:profile) { "|gitlab-org|gitlab-ce_#{Time.now.to_i}_memory.txt" }
|
2017-04-30 18:29:34 -04:00
|
|
|
|
2019-06-27 09:42:14 -04:00
|
|
|
it 'displays the content' do
|
|
|
|
visit admin_requests_profile_path(profile)
|
2017-04-30 18:29:34 -04:00
|
|
|
|
2019-06-27 09:42:14 -04:00
|
|
|
expect(page).to have_content(content)
|
|
|
|
end
|
2017-04-30 18:29:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a profile does not exist' do
|
|
|
|
it 'shows an error message' do
|
|
|
|
visit admin_requests_profile_path('|non|existent_12345.html')
|
|
|
|
|
|
|
|
expect(page).to have_content('Profile not found')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|