Skip to content

Commit

Permalink
fix: parallel timeout improvements (#5859)
Browse files Browse the repository at this point in the history
feat: improve timeouts in test suite

feat: add per test timeout based on ENV variable
we have lots of issues with tests hanging but us being unsure which
test hung. This will allow us to set a max time for test and get
feedback on which ones are timing out.

feat: fail fast docker ci
docker is used mainly as a verification step. It should only give info
about docker itself working or not. Might as well make it fail fast.

fix: change queue_adapter
lots of failures seem to stem from background jobs, fixing the
queue_adapter is a suggested step
  • Loading branch information
elasticspoon authored Jul 6, 2024
1 parent 64f8c36 commit d057a38
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
timeout-minutes: 20
env:
RAILS_ENV: test
TEST_MAX_DURATION: 60
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -37,7 +38,7 @@ jobs:
- name: compile assets
run: docker-compose exec -T web bundle exec rails assets:precompile
- name: Test
run: docker-compose exec -T web bundle exec rspec spec --format documentation
run: docker-compose exec -T web bundle exec rspec spec --fail-fast

- name: Archive selenium screenshots
if: ${{ failure() }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
timeout-minutes: 20
env:
RAILS_ENV: test
TEST_MAX_DURATION: 60

services:
db:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/rspec_parallel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
rspec_parallel:
name: RSpec Groups ${{ inputs.groups }}
runs-on: ubuntu-latest
timeout-minutes: 4
env:
RAILS_ENV: test
TEST_MAX_DURATION: 45
BUNDLE_WITHOUT: "development"
CI_TOTAL_JOBS: ${{ inputs.group_count }}
CI_JOB_INDEX: ${{ inputs.groups }}
Expand Down Expand Up @@ -110,12 +110,10 @@ jobs:
RUBYOPT='-W:no-deprecated -W:no-experimental' bundle exec parallel_rspec \
-n "${CI_TOTAL_JOBS}" \
--only-group "${CI_JOB_INDEX}" \
--runtime-log old_parallel_runtime.log \
--verbose ./spec
--runtime-log old_parallel_runtime.log ./spec
# echo 'Tests completed. Uploading to Code Climate'
# ./cc-test-reporter after-build --exit-code $?
# cat tmp/spec_summary.log
- name: Compress reports
if: ${{ !cancelled() }}
Expand Down
3 changes: 1 addition & 2 deletions .rspec_parallel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
--format RspecJunitFormatter --out tmp/reports/rspec_<%= ENV["GROUPS_UNDERSCORE"] %>_<%= ENV["TEST_ENV_NUMBER"] %>.xml
--format ParallelTests::RSpec::VerboseLogger
--format ParallelTests::RSpec::SummaryLogger
--format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime.log
--format ParallelTests::RSpec::SummaryLogger --out tmp/spec_summary.log
--format ParallelTests::RSpec::FailuresLogger --out tmp/failing_specs.log
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@

# Raise error when a before_action's only/except options reference missing actions
config.action_controller.raise_on_missing_callback_actions = false

# https://github.com/rails/rails/issues/48468
config.active_job.queue_adapter = :test
end
9 changes: 9 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@

config.disable_monkey_patching!

config.around :each do |example|
# If timeout is not set it will run without a timeout
Timeout.timeout(ENV["TEST_MAX_DURATION"].to_i) do
example.run
end
rescue Timeout::Error
raise StandardError.new "\"#{example.full_description}\" in #{example.location} timed out."
end

config.around :each, :disable_bullet do |example|
Bullet.raise = false
example.run
Expand Down

0 comments on commit d057a38

Please sign in to comment.