From c8239cf01e1e85fda76ba1685dbb478a1bb56607 Mon Sep 17 00:00:00 2001 From: "Ben Sheldon [he/him]" Date: Tue, 31 Oct 2023 14:23:55 -0700 Subject: [PATCH] In test, shutdown schedulers/capsules before doing assertions because of race conditions; store CI logs for Dev Env tests --- .github/workflows/test.yml | 15 +++++++++++++++ spec/integration/capsule_spec.rb | 5 +++-- spec/integration/complex_jobs_spec.rb | 20 +++++++++++++++++--- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 33407be74..14959cd2d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/spec/integration/capsule_spec.rb b/spec/integration/capsule_spec.rb index 3c10ff486..934e3b088 100644 --- a/spec/integration/capsule_spec.rb +++ b/spec/integration/capsule_spec.rb @@ -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 diff --git a/spec/integration/complex_jobs_spec.rb b/spec/integration/complex_jobs_spec.rb index d37c45074..2661d7867 100644 --- a/spec/integration/complex_jobs_spec.rb +++ b/spec/integration/complex_jobs_spec.rb @@ -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. @@ -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, @@ -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, @@ -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, @@ -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, @@ -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,