Commit 2b78774a authored by Robert Speicher's avatar Robert Speicher

Merge branch '23034-enable-rspec-profiling' into 'master'

Add rspec_profiling to the rspec environment

Closes #23034

See merge request !7854
parents 437722be f83b8bd4
...@@ -280,6 +280,7 @@ group :development, :test do ...@@ -280,6 +280,7 @@ group :development, :test do
gem 'rspec-retry', '~> 0.4.5' gem 'rspec-retry', '~> 0.4.5'
gem 'spinach-rails', '~> 0.2.1' gem 'spinach-rails', '~> 0.2.1'
gem 'spinach-rerun-reporter', '~> 0.0.2' gem 'spinach-rerun-reporter', '~> 0.0.2'
gem 'rspec_profiling'
# Prevent occasions where minitest is not bundled in packaged versions of ruby (see #3826) # Prevent occasions where minitest is not bundled in packaged versions of ruby (see #3826)
gem 'minitest', '~> 5.7.0' gem 'minitest', '~> 5.7.0'
......
...@@ -642,6 +642,11 @@ GEM ...@@ -642,6 +642,11 @@ GEM
rspec-retry (0.4.5) rspec-retry (0.4.5)
rspec-core rspec-core
rspec-support (3.5.0) rspec-support (3.5.0)
rspec_profiling (0.0.4)
activerecord
pg
rails
sqlite3
rubocop (0.46.0) rubocop (0.46.0)
parser (>= 2.3.1.1, < 3.0) parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1) powerpack (~> 0.1)
...@@ -743,6 +748,7 @@ GEM ...@@ -743,6 +748,7 @@ GEM
actionpack (>= 4.0) actionpack (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sqlite3 (1.3.11)
stackprof (0.2.10) stackprof (0.2.10)
state_machines (0.4.0) state_machines (0.4.0)
state_machines-activemodel (0.4.0) state_machines-activemodel (0.4.0)
...@@ -965,6 +971,7 @@ DEPENDENCIES ...@@ -965,6 +971,7 @@ DEPENDENCIES
rqrcode-rails3 (~> 0.1.7) rqrcode-rails3 (~> 0.1.7)
rspec-rails (~> 3.5.0) rspec-rails (~> 3.5.0)
rspec-retry (~> 0.4.5) rspec-retry (~> 0.4.5)
rspec_profiling
rubocop (~> 0.46.0) rubocop (~> 0.46.0)
rubocop-rspec (~> 1.9.1) rubocop-rspec (~> 1.9.1)
ruby-fogbugz (~> 0.2.1) ruby-fogbugz (~> 0.2.1)
......
module RspecProfilingConnection
def establish_connection
::RspecProfiling::Collectors::PSQL::Result.establish_connection(ENV['RSPEC_PROFILING_POSTGRES_URL'])
end
end
if Rails.env.test?
RspecProfiling.configure do |config|
if ENV['RSPEC_PROFILING_POSTGRES_URL']
RspecProfiling::Collectors::PSQL.prepend(RspecProfilingConnection)
config.collector = RspecProfiling::Collectors::PSQL
end
end
end
...@@ -211,6 +211,41 @@ suite first. See the ...@@ -211,6 +211,41 @@ suite first. See the
[StackProf documentation](https://github.com/tmm1/stackprof/blob/master/README.md) [StackProf documentation](https://github.com/tmm1/stackprof/blob/master/README.md)
for details. for details.
## RSpec profiling
GitLab's development environment also includes the
[rspec_profiling](https://github.com/foraker/rspec_profiling) gem, which is used
to collect data on spec execution times. This is useful for analyzing the
performance of the test suite itself, or seeing how the performance of a spec
may have changed over time.
To activate profiling in your local environment, run the following:
```
$ export RSPEC_PROFILING=yes
$ rake rspec_profiling:install
```
This creates an SQLite3 database in `tmp/rspec_profiling`, into which statistics
are saved every time you run specs with the `RSPEC_PROFILING` environment
variable set.
Ad-hoc investigation of the collected results can be performed in an interactive
shell:
```
$ rake rspec_profiling:console
irb(main):001:0> results.count
=> 231
irb(main):002:0> results.last.attributes.keys
=> ["id", "commit", "date", "file", "line_number", "description", "time", "status", "exception", "query_count", "query_time", "request_count", "request_time", "created_at", "updated_at"]
irb(main):003:0> results.where(status: "passed").average(:time).to_s
=> "0.211340155844156"
```
These results can also be placed into a PostgreSQL database by setting the
`RSPEC_PROFILING_POSTGRES_URL` variable. This is used to profile the test suite
when running in the CI environment.
## Importance of Changes ## Importance of Changes
When working on performance improvements, it's important to always ask yourself When working on performance improvements, it's important to always ask yourself
......
...@@ -9,6 +9,10 @@ require 'rspec/rails' ...@@ -9,6 +9,10 @@ require 'rspec/rails'
require 'shoulda/matchers' require 'shoulda/matchers'
require 'rspec/retry' require 'rspec/retry'
if ENV['RSPEC_PROFILING_POSTGRES_URL'] || ENV['RSPEC_PROFILING']
require 'rspec_profiling/rspec'
end
if ENV['CI'] && !ENV['NO_KNAPSACK'] if ENV['CI'] && !ENV['NO_KNAPSACK']
require 'knapsack' require 'knapsack'
Knapsack::Adapters::RSpecAdapter.bind Knapsack::Adapters::RSpecAdapter.bind
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment