brandonhilkert / sucker_punch

Sucker Punch is a Ruby asynchronous processing library using concurrent-ruby, heavily influenced by Sidekiq and girl_friday.
MIT License
2.64k stars 114 forks source link

ActiveJob TestHelper assert methods causes stack level too deep #124

Closed trandoanhung1991 closed 9 years ago

trandoanhung1991 commented 9 years ago

I'm trying to use Sucker punch via Active Job for async devise mail deliveries. However, I'm having trouble testing due to this problem. FWIW, SP works fine, it's just the testing where it crashes.

rails_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'shoulda/matchers'
require 'database_cleaner'
require 'sucker_punch/testing/inline'

ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|
  # config.use_transactional_fixtures = true

  config.include FactoryGirl::Syntax::Methods
  config.include Devise::TestHelpers, type: :controller

  config.infer_spec_type_from_file_location!

  config.before(:suite) do
    DatabaseCleaner.clean_with :truncation
    DatabaseCleaner.strategy = :transaction
  end

  config.around(:each) do |spec|
    DatabaseCleaner.cleaning do
      spec.run
    end
  end
end

config/initializers/sucker_punch.rb

SuckerPunch.exception_handler { |ex| ExceptionNotifier.notify_exception(ex) }
Rails.application.configure do
  config.active_job.queue_adapter = :sucker_punch
end

spec file

require 'rails_helper'
include ActiveJob::TestHelper
RSpec.describe Model, type: :model do

  describe '#sample' do
    it 'crashes' do
      assert_enqueued_jobs 0
    end
end
Failure/Error: assert_enqueued_jobs 0 do
     SystemStackError:
       stack level too deep
     # .../gems/activejob-4.2.3/lib/active_job/test_helper.rb:208:in `rescue in enqueued_jobs'
     # .../gems/activejob-4.2.3/lib/active_job/test_helper.rb:208:in `enqueued_jobs'

The only way I can get testing to work is to use Active Job's :test adapter via checking Rails.env.test? in sucker_punch.rb

brandonhilkert commented 9 years ago

Does this same error happen if you use Sucker Punch without Activejob?

trandoanhung1991 commented 9 years ago

I haven't tried that yet. But so far my workaround works so I haven't the motivation to mess with it further.

How would I go about replicating a similar condition without using ActiveJob as the middleman?

brandonhilkert commented 9 years ago

Installing sucker punch per the readme and using the test helper to assert your job was run.

On Tuesday, August 25, 2015, Hung Tran notifications@github.com wrote:

I haven't tried that yet. But so far my workaround works so I haven't the motivation to mess with it further.

How would I go about replicating a similar condition without using ActiveJob as the middleman?

— Reply to this email directly or view it on GitHub https://github.com/brandonhilkert/sucker_punch/issues/124#issuecomment-134508846 .


_Build a Ruby Gem is available! http://brandonhilkert.com/books/build-a-ruby-gem/?utm_source=gmail-sig&utm_medium=email&utm_campaign=gmail_

http://brandonhilkert.com