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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
4085428e
Commit
4085428e
authored
Jul 12, 2019
by
Aleksei Lipniagov
Committed by
Kamil Trzciński
Jul 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gather memory usage data in tests
Log memory stats after running each spec file and compile the report.
parent
1def0719
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
0 deletions
+86
-0
.gitlab/ci/rails.gitlab-ci.yml
.gitlab/ci/rails.gitlab-ci.yml
+5
-0
scripts/gather-test-memory-data
scripts/gather-test-memory-data
+21
-0
spec/spec_helper.rb
spec/spec_helper.rb
+1
-0
spec/support/helpers/memory_usage_helper.rb
spec/support/helpers/memory_usage_helper.rb
+37
-0
spec/support/helpers/test_env.rb
spec/support/helpers/test_env.rb
+22
-0
No files found.
.gitlab/ci/rails.gitlab-ci.yml
View file @
4085428e
...
...
@@ -66,6 +66,8 @@
-
scripts/gitaly-test-spawn
-
date
-
'
export
KNAPSACK_TEST_FILE_PATTERN=$(ruby
-r./lib/quality/test_level.rb
-e
"puts
Quality::TestLevel.new.pattern(:${TEST_LEVEL})")'
-
mkdir -p tmp/memory_test
-
export MEMORY_TEST_PATH="tmp/memory_test/${TEST_TOOL}_${TEST_LEVEL}_${DATABASE}_node_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_memory.csv"
-
knapsack rspec "--color --format documentation --format RspecJunitFormatter --out junit_rspec.xml --tag level:${TEST_LEVEL} --tag ~geo"
-
date
artifacts
:
...
...
@@ -77,6 +79,7 @@
-
rspec_flaky/
-
rspec_profiling/
-
tmp/capybara/
-
tmp/memory_test/
# reports:
# junit: junit_rspec.xml
...
...
@@ -273,6 +276,7 @@ coverage:
stage
:
post-test
script
:
-
bundle exec scripts/merge-simplecov
-
bundle exec scripts/gather-test-memory-data
coverage
:
'
/LOC
\((\d+\.\d+%)\)
covered.$/'
artifacts
:
name
:
coverage
...
...
@@ -280,3 +284,4 @@ coverage:
paths
:
-
coverage/index.html
-
coverage/assets/
-
tmp/memory_test/
scripts/gather-test-memory-data
0 → 100755
View file @
4085428e
#!/usr/bin/env ruby
require
'csv'
def
join_csv_files
(
output_path
,
input_paths
)
return
if
input_paths
.
empty?
input_csvs
=
input_paths
.
map
do
|
input_path
|
CSV
.
read
(
input_path
,
headers:
true
)
end
CSV
.
open
(
output_path
,
"w"
,
headers:
input_csvs
.
first
.
headers
,
write_headers:
true
)
do
|
output_csv
|
input_csvs
.
each
do
|
input_csv
|
input_csv
.
each
do
|
line
|
output_csv
<<
line
end
end
end
end
join_csv_files
(
'tmp/memory_test/report.csv'
,
Dir
[
'tmp/memory_test/*.csv'
].
sort
)
spec/spec_helper.rb
View file @
4085428e
...
...
@@ -103,6 +103,7 @@ RSpec.configure do |config|
config
.
include
RedisHelpers
config
.
include
Rails
.
application
.
routes
.
url_helpers
,
type: :routing
config
.
include
PolicyHelpers
,
type: :policy
config
.
include
MemoryUsageHelper
if
ENV
[
'CI'
]
# This includes the first try, i.e. tests will be run 4 times before failing.
...
...
spec/support/helpers/memory_usage_helper.rb
0 → 100644
View file @
4085428e
# frozen_string_literal: true
module
MemoryUsageHelper
extend
ActiveSupport
::
Concern
def
gather_memory_data
(
csv_path
)
write_csv_entry
(
csv_path
,
{
example_group_path:
TestEnv
.
topmost_example_group
[
:location
],
example_group_description:
TestEnv
.
topmost_example_group
[
:description
],
time:
Time
.
current
,
job_name:
ENV
[
'CI_JOB_NAME'
]
}.
merge
(
get_memory_usage
))
end
def
write_csv_entry
(
path
,
entry
)
CSV
.
open
(
path
,
"a"
,
headers:
entry
.
keys
,
write_headers:
!
File
.
exist?
(
path
))
do
|
file
|
file
<<
entry
.
values
end
end
def
get_memory_usage
output
,
status
=
Gitlab
::
Popen
.
popen
(
%w(free -m)
)
abort
"`free -m` return code is
#{
status
}
:
#{
output
}
"
unless
status
.
zero?
result
=
output
.
split
(
"
\n
"
)[
1
].
split
(
" "
)[
1
..-
1
]
attrs
=
%i(m_total m_used m_free m_shared m_buffers_cache m_available)
.
freeze
attrs
.
zip
(
result
).
to_h
end
included
do
|
config
|
config
.
after
(
:all
)
do
gather_memory_data
(
ENV
[
'MEMORY_TEST_PATH'
])
if
ENV
[
'MEMORY_TEST_PATH'
]
end
end
end
spec/support/helpers/test_env.rb
View file @
4085428e
...
...
@@ -2,6 +2,7 @@ require 'rspec/mocks'
require
'toml-rb'
module
TestEnv
extend
ActiveSupport
::
Concern
extend
self
ComponentFailedToInstallError
=
Class
.
new
(
StandardError
)
...
...
@@ -108,6 +109,12 @@ module TestEnv
setup_forked_repo
end
included
do
|
config
|
config
.
append_before
do
set_current_example_group
end
end
def
disable_mailer
allow_any_instance_of
(
NotificationService
).
to
receive
(
:mailer
)
.
and_return
(
double
.
as_null_object
)
...
...
@@ -297,8 +304,23 @@ module TestEnv
FileUtils
.
rm_rf
(
path
)
end
def
current_example_group
Thread
.
current
[
:current_example_group
]
end
# looking for a top-level `describe`
def
topmost_example_group
example_group
=
current_example_group
example_group
=
example_group
[
:parent_example_group
]
until
example_group
[
:parent_example_group
].
nil?
example_group
end
private
def
set_current_example_group
Thread
.
current
[
:current_example_group
]
=
::
RSpec
.
current_example
.
metadata
[
:example_group
]
end
# These are directories that should be preserved at cleanup time
def
test_dirs
@test_dirs
||=
%w[
...
...
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