Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize test suite, CI config (#866)
Optimizes the test suite and CI config for performance ### Local improvements: Speeds up local test runs by ~95% (given sufficient parallelization — 7:14 to 0:21 on my machine): - Adds `parallel_tests` to parallelize the test suite (best results found at 1 process per core, details below) - Adds `spring` to pre-load the application. Also speeds up rake, non-parallel test runs, etc - Changes database cleaner strategy to default to transactions ([granularly overridable](https://github.com/bikeindex/bike_index/blob/538a1d924e43e18556069580c1cedc34c852aeb7/spec/support/database_cleaner.rb)) [more on [db cleaning strategies](https://stackoverflow.com/questions/11419536/postgresql-truncation-speed/11423886#11423886)] ### CI config changes - Reduces parallelism to [2 nodes](538a1d9), which improves throughput across multiple builds (see below) - Caches [more granularly](a89c345) (separate caches for Ruby and Node dependencies, and for precompiled assets) ### RSpec updates In line with upstream deprecations: - Refactors to remove global render_views setting - Disables monkey patching - Disables inferring test type from directory - Use "rails_helper" instead of "spec_helper" (the latter should be used for any non-rails code) ### Usage To run the RSpec suite in parallel, set up databases with ``` bin/rake parallel:setup ``` and run with ``` bin/rake parallel:spec ``` You can override the default number of processes with the following env vars: ``` export PARALLEL_TEST_PROCESSORS=XX ``` Set [`export DISABLE_SPRING=0`](https://github.com/grosser/parallel_tests/wiki/Spring) to speed up app boot time when running tests in parallel.
- Loading branch information
Jake Romer
committed
Jun 9, 2019
1 parent
29acdb2
commit db52a54
Showing
274 changed files
with
1,183 additions
and
594 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,7 @@ yarn-error.log | |
|
||
# Ignore jest coverage files | ||
coverage | ||
|
||
# Ignore test results | ||
test-results/ | ||
spec/examples.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--require rails_helper | ||
|
||
--no-profile | ||
--order random | ||
|
||
--format progress | ||
|
||
--format ParallelTests::RSpec::SummaryLogger | ||
--out tmp/parallel_spec_summary.log | ||
|
||
--format ParallelTests::RSpec::RuntimeLogger | ||
--out tmp/parallel_runtime_rspec.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,44 @@ | ||
group :red_green_refactor, halt_on_fail: true do | ||
guard :rspec, cmd: 'bundle exec rspec', failed_mode: :focus do | ||
rspec_options = { | ||
cmd: "bin/rspec -f progress", | ||
cmd_additional_args: "--require rails_helper --no-profile --order defined", | ||
run_all: { | ||
cmd: "bin/parallel_rspec --quiet --test-options='-f documentation -o /dev/null -f progress", | ||
cmd_additional_args: "'", | ||
}, | ||
failed_mode: :focus, | ||
} | ||
|
||
guard :rspec, rspec_options do | ||
watch(%r{^spec/.+_spec\.rb$}) | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
watch(%r{^config/initializers/(.+)\.rb$}) { |m| "spec/initializers/#{m[1]}_spec.rb" } | ||
watch('spec/spec_helper.rb') { "spec" } | ||
watch(%r{^app/controllers/api/v2/(.+)\.rb$}) { |m| "spec/requests/api/v2/#{m[1]}_spec.rb"} | ||
watch(%r{^app/controllers/api/v3/(.+)\.rb$}) { |m| "spec/requests/api/v3/#{m[1]}_spec.rb"} | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
watch(%r{^config/initializers/(.+)\.rb$}) { |m| "spec/initializers/#{m[1]}_spec.rb" } | ||
|
||
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } | ||
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } | ||
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/controllers/#{m[1]}_#{m[2]}_spec.rb" } | ||
# watch(%r{^spec/support/(.+)\.rb$}) { "spec" } # Stop running all specs on shared_example update | ||
watch('config/routes.rb') { "spec/routing" } | ||
watch('app/controllers/application_controller.rb') { "spec/controllers" } | ||
end | ||
watch("spec/spec_helper.rb") { "spec" } | ||
watch("spec/rails_helper.rb") { "spec" } | ||
|
||
watch(%r{^app/controllers/api/v2/(.+)\.rb$}) { |m| "spec/requests/api/v2/#{m[1]}_spec.rb" } | ||
watch(%r{^app/controllers/api/v3/(.+)\.rb$}) { |m| "spec/requests/api/v3/#{m[1]}_spec.rb" } | ||
|
||
guard :rubocop, all_on_start: false do | ||
watch(%r{^app/(.+)\.rb$}) | ||
watch(%r{^spec/(.+)\.rb$}) | ||
watch(%r{^config/(.+)\.rb$}) | ||
watch(%r{^lib/(.+)\.rb$}) | ||
watch(%r{^lib/(.+)\.rake$}) | ||
watch(%r{^db/(.+)\.rb$}) | ||
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } | ||
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } | ||
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } | ||
|
||
watch("config/routes.rb") { "spec/routing" } | ||
watch("app/controllers/application_controller.rb") { "spec/controllers" } | ||
|
||
watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "spec/requests/#{m[1]}_request_spec.rb" } | ||
watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "spec/requests/#{m[1]}_controller_spec.rb" } | ||
end | ||
end | ||
end | ||
|
||
# group :linting, halt_on_fail: true do | ||
# guard :rubocop, all_on_start: false do | ||
# watch(%r{^app/(.+)\.rb$}) | ||
# watch(%r{^spec/(.+)\.rb$}) | ||
# watch(%r{^config/(.+)\.rb$}) | ||
# watch(%r{^lib/(.+)\.rb$}) | ||
# watch(%r{^lib/(.+)\.rake$}) | ||
# watch(%r{^db/(.+)\.rb$}) | ||
# watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } | ||
# end | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
web: bundle exec unicorn_rails -p 3001 | ||
webpacker: ./bin/webpack-dev-server # Live update webpack js | ||
log: tail -f log/development.log | ||
hard_worker: bundle exec rerun --background --dir app,db,lib --pattern '{**/*.rb}' -- bundle exec sidekiq | ||
hard_worker: bundle exec rerun --background --dir app,db,lib --pattern '{**/*.rb}' -- bundle exec sidekiq |
Oops, something went wrong.