Skip to content

Commit

Permalink
feat: add timeouts to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticspoon committed Jul 5, 2024
1 parent 64f8c36 commit fecd0c7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 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

- 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
7 changes: 3 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,11 @@ 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
cat tmp/spec_summary.log
- name: Compress reports
if: ${{ !cancelled() }}
Expand Down
1 change: 0 additions & 1 deletion .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::RuntimeLogger --out tmp/parallel_runtime.log
--format ParallelTests::RSpec::SummaryLogger --out tmp/spec_summary.log
--format ParallelTests::RSpec::FailuresLogger --out tmp/failing_specs.log
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 "\nTimout Error: example #{example.full_description} timed out.\n"
end

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

0 comments on commit fecd0c7

Please sign in to comment.