Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
13de8aee
Commit
13de8aee
authored
May 01, 2017
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for Gitlab::RequestProfiler
Closes #31513
parent
03f13af5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
0 deletions
+140
-0
spec/features/admin/admin_requests_profiles_spec.rb
spec/features/admin/admin_requests_profiles_spec.rb
+69
-0
spec/lib/gitlab/request_profiler_spec.rb
spec/lib/gitlab/request_profiler_spec.rb
+27
-0
spec/requests/request_profiler_spec.rb
spec/requests/request_profiler_spec.rb
+44
-0
No files found.
spec/features/admin/admin_requests_profiles_spec.rb
0 → 100644
View file @
13de8aee
require
'spec_helper'
describe
'Admin::RequestsProfilesController'
,
feature:
true
do
before
do
FileUtils
.
mkdir_p
(
Gitlab
::
RequestProfiler
::
PROFILES_DIR
)
login_as
(
:admin
)
end
after
do
Gitlab
::
RequestProfiler
.
remove_all_profiles
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
it
'lists all available profiles'
do
time1
=
1
.
hour
.
ago
time2
=
2
.
hours
.
ago
time3
=
3
.
hours
.
ago
profile1
=
"|gitlab-org|gitlab-ce_
#{
time1
.
to_i
}
.html"
profile2
=
"|gitlab-org|gitlab-ce_
#{
time2
.
to_i
}
.html"
profile3
=
"|gitlab-com|infrastructure_
#{
time3
.
to_i
}
.html"
FileUtils
.
touch
(
"
#{
Gitlab
::
RequestProfiler
::
PROFILES_DIR
}
/
#{
profile1
}
"
)
FileUtils
.
touch
(
"
#{
Gitlab
::
RequestProfiler
::
PROFILES_DIR
}
/
#{
profile2
}
"
)
FileUtils
.
touch
(
"
#{
Gitlab
::
RequestProfiler
::
PROFILES_DIR
}
/
#{
profile3
}
"
)
visit
admin_requests_profiles_path
within
(
'.panel'
,
text:
'/gitlab-org/gitlab-ce'
)
do
expect
(
page
).
to
have_selector
(
"a[href='
#{
admin_requests_profile_path
(
profile1
)
}
']"
,
text:
time1
.
to_s
(
:long
))
expect
(
page
).
to
have_selector
(
"a[href='
#{
admin_requests_profile_path
(
profile2
)
}
']"
,
text:
time2
.
to_s
(
:long
))
end
within
(
'.panel'
,
text:
'/gitlab-com/infrastructure'
)
do
expect
(
page
).
to
have_selector
(
"a[href='
#{
admin_requests_profile_path
(
profile3
)
}
']"
,
text:
time3
.
to_s
(
:long
))
end
end
end
describe
'GET /admin/requests_profiles/:profile'
do
context
'when a profile exists'
do
it
'displays the content of the profile'
do
content
=
'This is a request profile'
profile
=
"|gitlab-org|gitlab-ce_
#{
Time
.
now
.
to_i
}
.html"
File
.
write
(
"
#{
Gitlab
::
RequestProfiler
::
PROFILES_DIR
}
/
#{
profile
}
"
,
content
)
visit
admin_requests_profile_path
(
profile
)
expect
(
page
).
to
have_content
(
content
)
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
spec/lib/gitlab/request_profiler_spec.rb
0 → 100644
View file @
13de8aee
require
'spec_helper'
describe
Gitlab
::
RequestProfiler
,
lib:
true
do
describe
'.profile_token'
do
it
'returns a token'
do
expect
(
described_class
.
profile_token
).
to
be_present
end
it
'caches the token'
do
expect
(
Rails
.
cache
).
to
receive
(
:fetch
).
with
(
'profile-token'
)
described_class
.
profile_token
end
end
describe
'.remove_all_profiles'
do
it
'removes Gitlab::RequestProfiler::PROFILES_DIR directory'
do
dir
=
described_class
::
PROFILES_DIR
FileUtils
.
mkdir_p
(
dir
)
expect
(
Dir
.
exist?
(
dir
)).
to
be
true
described_class
.
remove_all_profiles
expect
(
Dir
.
exist?
(
dir
)).
to
be
false
end
end
end
spec/requests/request_profiler_spec.rb
0 → 100644
View file @
13de8aee
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment