Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rspec-benchmark capabilities to test performance in rspecs #3453

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ group :test do
gem 'rack-test'
gem 'rspec', '~> 3.12.0'
gem 'rspec_api_documentation', '>= 6.1.0'
gem 'rspec-benchmark', '~> 0.6.0'
gem 'rspec-collection_matchers'
gem 'rspec-instafail'
gem 'rspec-its'
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ GEM
base64 (0.1.1)
beefcake (1.0.0)
benchmark (0.2.1)
benchmark-malloc (0.2.0)
benchmark-perf (0.6.0)
benchmark-trend (0.4.0)
bigdecimal (3.1.4)
bit-struct (0.17)
builder (3.2.4)
Expand Down Expand Up @@ -415,6 +418,11 @@ GEM
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-benchmark (0.6.0)
benchmark-malloc (~> 0.2)
benchmark-perf (~> 0.6)
benchmark-trend (~> 0.4)
rspec (>= 3.0)
rspec-collection_matchers (1.2.0)
rspec-expectations (>= 2.99.0.beta1)
rspec-core (3.12.2)
Expand Down Expand Up @@ -630,6 +638,7 @@ DEPENDENCIES
rfc822
roodi
rspec (~> 3.12.0)
rspec-benchmark (~> 0.6.0)
rspec-collection_matchers
rspec-instafail
rspec-its
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
require 'rspec/collection_matchers'
require 'rspec/its'
require 'rspec/wait'
require 'rspec-benchmark'
end

each_run_block = proc do
Expand All @@ -93,6 +94,7 @@
mocks.verify_partial_doubles = true
end
rspec_config.filter_run_excluding :stepper
rspec_config.filter_run_excluding :perf
rspec_config.expose_dsl_globally = false
rspec_config.backtrace_exclusion_patterns = [%r{/gems/}, %r{/bin/rspec}]

Expand Down Expand Up @@ -127,6 +129,8 @@

rspec_config.include SpaceRestrictedResponseGenerators

rspec_config.include RSpec::Benchmark::Matchers

rspec_config.before(:all) { WebMock.disable_net_connect!(allow: %w[codeclimate.com fake.bbs]) }
rspec_config.before(:all, type: :integration) do
WebMock.allow_net_connect!
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/controllers/v3/app_features_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
end
end

describe 'performance', :perf do
it 'returns in reasonable time' do
expect { get :index, params: { app_guid: app_model.guid } }.to perform_under(10).ms
end
end

it 'returns app features' do
get :index, params: { app_guid: app_model.guid }
expect(parsed_body).to eq(
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/controllers/v3/apps_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
set_current_user_as_admin(user:)
end

context 'performance', :perf do
it 'returns in reasonable time' do
expect { get :index, params: {} }.to perform_under(10).ms
end
end

context 'query params' do
context 'invalid param format' do
it 'returns 400' do
Expand Down