Skip to content

Commit f526f9d

Browse files
committed
CI: Run tests in parallel
GitHub Actions have two cores by default. Let's use them.
1 parent b65e378 commit f526f9d

6 files changed

Lines changed: 48 additions & 5 deletions

File tree

.github/workflows/build_test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,12 @@ jobs:
200200
- name: Prepare database
201201
run: |
202202
bundle exec rake alchemy:spec:prepare
203+
cd spec/dummy
204+
bin/rails parallel:setup
205+
cd -
203206
- name: Run tests
204207
run: |
205-
bundle exec rspec
208+
bin/parallel_rspec
206209
- name: Upload coverage reports to Codecov
207210
uses: codecov/codecov-action@v5
208211
if: matrix.rails == '8.0' && matrix.ruby == '3.4'

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,34 @@ $ bundle exec rake
336336

337337
*) This default task executes the database preparations and runs all defined test cases.
338338

339+
### Run specs in parallel
340+
341+
Using https://github.com/grosser/parallel_tests
342+
343+
#### Once before running
344+
345+
```
346+
bundle exec rake alchemy:spec:prepare
347+
cd spec/dummy
348+
bin/rails parallel:setup
349+
cd -
350+
```
351+
352+
#### Start a parallel test run
353+
354+
```
355+
bin/parallel_rspec
356+
```
357+
358+
#### After adding a new migration
359+
360+
```
361+
cd spec/dummy
362+
bin/rails alchemy:install:migrations
363+
bin/rails parallel:migrate
364+
cd -
365+
```
366+
339367
### Start the dummy app
340368

341369
You can even start the dummy app and use it to manually test your changes with:

alchemy_cms.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Gem::Specification.new do |gem|
6262
gem.add_development_dependency "capybara-screenshot", ["~> 1.0"]
6363
gem.add_development_dependency "capybara-shadowdom", ["~> 0.3"]
6464
gem.add_development_dependency "factory_bot_rails", ["~> 6.0"]
65+
gem.add_development_dependency "parallel_tests", "~> 5.5"
6566
gem.add_development_dependency "puma", "~> 7.0"
6667
gem.add_development_dependency "rails-controller-testing", ["~> 1.0"]
6768
gem.add_development_dependency "rspec-activemodel-mocks", ["~> 1.0"]

bin/parallel_rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env ruby
2+
require "bundler/setup"
3+
load Gem.bin_path("parallel_tests", "parallel_rspec")

spec/dummy/config/database.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
sqlite: &sqlite
22
adapter: sqlite3
3-
database: db/<%= Rails.env %>.sqlite3
3+
database: db/<%= Rails.env %><%= ENV['TEST_ENV_NUMBER'] %>.sqlite3
44

55
mysql: &mysql
66
adapter: mysql2
77
encoding: utf8mb4
88
username: <%= ENV['DB_USER'] %>
99
password: <%= ENV['DB_PASSWORD'] %>
10-
database: alchemy_cms_dummy_<%= Rails.env %>
10+
database: alchemy_cms_dummy_<%= Rails.env %><%= ENV['TEST_ENV_NUMBER'] %>
1111

1212
mariadb: &mariadb
1313
adapter: mysql2
1414
encoding: utf8mb4
1515
port: 3307
1616
username: <%= ENV['DB_USER'] %>
1717
password: <%= ENV['DB_PASSWORD'] %>
18-
database: alchemy_cms_dummy_<%= Rails.env %>
18+
database: alchemy_cms_dummy_<%= Rails.env %><%= ENV['TEST_ENV_NUMBER'] %>
1919

2020
postgresql: &postgresql
2121
adapter: postgresql
2222
<% if ENV['DB_USER'] %>
2323
username: <%= ENV['DB_USER'] %>
2424
password: <%= ENV['DB_PASSWORD'] %>
2525
<% end %>
26-
database: alchemy_cms_dummy_<%= Rails.env %>
26+
database: alchemy_cms_dummy_<%= Rails.env %><%= ENV['TEST_ENV_NUMBER'] %>
2727
min_messages: ERROR
2828

2929
defaults: &defaults

spec/spec_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@
1212
add_filter "/lib/generators"
1313
end
1414

15+
if ENV["TEST_ENV_NUMBER"] # parallel specs
16+
SimpleCov.at_exit do
17+
result = SimpleCov.result
18+
result.format! if ParallelTests.number_of_running_processes <= 1
19+
end
20+
end
21+
1522
require "rspec/core"
1623

1724
RSpec.configure do |config|
1825
config.raise_errors_for_deprecations!
1926
config.run_all_when_everything_filtered = true
2027
config.pattern = "**/*_spec.rb"
2128
config.filter_run :focus
29+
config.silence_filter_announcements = true if ENV["TEST_ENV_NUMBER"]
2230
end

0 commit comments

Comments
 (0)