Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When running rspec, I get: current transaction is aborted, commands ignored until end of transaction block #595

Closed
rgaufman opened this issue May 11, 2022 · 1 comment

Comments

@rgaufman
Copy link

rgaufman commented May 11, 2022

I have this in my spec_helper.rb:

...
good_job_adapter = GoodJob::Adapter.new(execution_mode: :inline)
ActiveJob::Base.queue_adapter = good_job_adapter

config.after do
  DatabaseCleaner.clean
end
...

I have this in my job:

# Worker for testing new job queues, useful for unique worker setting testing
class TestJob < ApplicationJob
  include GoodJob::ActiveJobExtensions::Concurrency
  good_job_control_concurrency_with(total_limit: 1, key: -> { arguments.to_json })
  queue_as :status

  def perform(params)
    `sleep 1`
  end
end

This is my spec:

require 'rails_helper'

RSpec.describe TestJob, type: :job do
  it "Runs successfully" do
    described_class.perform_later({ test: 1 })
  end
end

However, I get:

  1) TestJob Runs successfully
     Got 0 failures and 2 other errors:

     1.1) Failure/Error: described_class.perform_later

          ActiveRecord::StatementInvalid:
            PG::InFailedSqlTransaction: ERROR:  current transaction is aborted, commands ignored until end of transaction block
          # ./spec/jobs/test_job_spec.rb:5:in `block (2 levels) in <top (required)>'
          # ./spec/spec_helper.rb:137:in `block (2 levels) in <top (required)>'
          # ------------------
          # --- Caused by: ---
          # PG::UndefinedTable:
          #   ERROR:  relation "good_jobs" does not exist
          #   LINE 9:  WHERE a.attrelid = '"good_jobs"'::regclass
          #                               ^
          #   ./spec/jobs/test_job_spec.rb:5:in `block (2 levels) in <top (required)>'

     1.2) Failure/Error: DatabaseCleaner.clean

          ActiveRecord::StatementInvalid:
            PG::InFailedSqlTransaction: ERROR:  current transaction is aborted, commands ignored until end of transaction block
          # ./spec/spec_helper.rb:120:in `block (2 levels) in <top (required)>'
          # ./spec/spec_helper.rb:137:in `block (2 levels) in <top (required)>'
          # ------------------
          # --- Caused by: ---
          # PG::InFailedSqlTransaction:
          #   ERROR:  current transaction is aborted, commands ignored until end of transaction block
          #   ./spec/spec_helper.rb:120:in `block (2 levels) in <top (required)>'

Any ideas? - any best practices for testing good_job jobs?

@rgaufman
Copy link
Author

Oh sorry, my mistake! - I missed an exception when running migrations, after migration it runs as expected, thank you for creating good_job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant