Skip to content

Commit

Permalink
In test, shutdown schedulers/capsules before doing assertions because…
Browse files Browse the repository at this point in the history
… of race conditions; store CI logs for Dev Env tests
  • Loading branch information
bensheldon committed Oct 31, 2023
1 parent ace3e42 commit c8239cf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ jobs:
run: bin/rails db:test:prepare
- name: bin/rspec
run: bin/rspec --require ./spec/support/pre_documentation_formatter.rb --format PreDocumentationFormatter
# Archive
- name: Archive system spec screenshots
uses: actions/upload-artifact@v3
if: failure()
with:
name: screenshots
path: |
spec/test_app/tmp/screenshots
spec/test_app/tmp/capybara
- name: Archive Rails logs
uses: actions/upload-artifact@v3
if: failure()
with:
name: rails_logs
path: spec/test_app/log

test:
name: Test
Expand Down
5 changes: 3 additions & 2 deletions spec/integration/capsule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def perform

LATCH.wait(10)
wait_until { expect(GoodJob::Job.finished.count).to eq(total_jobs) }
expect(GoodJob::DiscreteExecution.count).to eq(total_jobs)

perform_capsule.shutdown
enqueue_capsule.shutdown

expect(GoodJob::DiscreteExecution.count).to eq(total_jobs)
end
end
20 changes: 17 additions & 3 deletions spec/integration/complex_jobs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
require 'rails_helper'

RSpec.describe 'Complex Jobs' do
let(:inline_adapter) { GoodJob::Adapter.new(execution_mode: :inline) }
let(:async_adapter) { GoodJob::Adapter.new(execution_mode: :async_all) }
let(:capsule) { GoodJob::Capsule.new }
let(:inline_adapter) { GoodJob::Adapter.new(execution_mode: :inline, _capsule: capsule) }
let(:async_adapter) { GoodJob::Adapter.new(execution_mode: :async_all, _capsule: capsule) }

before do
GoodJob.capsule.restart
allow(GoodJob.on_thread_error).to receive(:call).and_call_original
end

after do
capsule.shutdown
end

describe 'Job without error handler / unhandled' do
after do
# This spec will intentionally raise an error on the thread.
Expand All @@ -28,6 +32,8 @@ def perform
TestJob.perform_later

wait_until { expect(GoodJob::Job.last.finished_at).to be_present }
capsule.shutdown

good_job = GoodJob::Job.last
expect(good_job).to have_attributes(
executions_count: 1,
Expand Down Expand Up @@ -64,6 +70,8 @@ def perform
TestJob.perform_later

wait_until { expect(GoodJob::Job.last.finished_at).to be_present }
capsule.shutdown

good_job = GoodJob::Job.last
expect(good_job).to have_attributes(
executions_count: 1,
Expand Down Expand Up @@ -94,6 +102,8 @@ def perform
TestJob.perform_later

wait_until { expect(GoodJob::Job.last.finished_at).to be_present }
capsule.shutdown

good_job = GoodJob::Job.last
expect(good_job).to have_attributes(
executions_count: 1,
Expand Down Expand Up @@ -124,6 +134,8 @@ def perform
TestJob.perform_later

wait_until { expect(GoodJob::Job.last.finished_at).to be_present }
capsule.shutdown

good_job = GoodJob::Job.last
expect(good_job).to have_attributes(
executions_count: 2,
Expand Down Expand Up @@ -151,6 +163,8 @@ def perform
TestJob.perform_later

wait_until { expect(GoodJob::Job.last.finished_at).to be_present }
capsule.shutdown

good_job = GoodJob::Job.last
expect(good_job).to have_attributes(
executions_count: 2,
Expand Down

0 comments on commit c8239cf

Please sign in to comment.