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

have_enqueued_job rspec matcher does not work with :karafka ActiveJob queue_adapter #140

Open
wahlg opened this issue Apr 21, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@wahlg
Copy link

wahlg commented Apr 21, 2023

If you configure a Rails application to use the karafka queue adapter as described in https://karafka.io/docs/Active-Job/, then when writing rspec tests that use the have_enqueued_job matcher, they will fail reporting no jobs were enqueued


Expected behavior

When configuring rails to use the karafka ActiveJob adapter with:

config.active_job.queue_adapter = :karafka

Then if I write ruby code to publish a job:

class SomeJob < ApplicationJob
  def perform
    puts "performed"
  end
end

SomeJob.perform_later

I expect an rspec test like this to pass:

expect do 
  SomeJob.perform_later
end.to have_enqueued_job(SomeJob).once

Actual behavior

The rspec test fails with

expected to enqueue exactly 1 jobs, but enqueued 0

I also observed this happens regardless of whether I use the produce_sync option or not

karafka_options(
  dispatch_method: :produce_sync
)

Steps to reproduce the problem

Create a rails 7 application, and configure it to use the :karafka queue adapter for ActiveJob as per above

Set up the karafka gem

Write a test that enqueues a job

See that it fails to report enqueueing the job

Your setup details

I am using Rails 7.0.4.3 and rspec 3.12.0

Karafka info is below:

$ [bundle exec] karafka info
2023-04-21 09:30:25.307444 I [65649:57120] Rails -- Karafka version: 2.0.38
Ruby version: ruby 3.2.1 (2023-02-08 revision 31819e82c8) +YJIT [arm64-darwin22]
Rdkafka version: 0.12.1
Consumer groups count: 4
Subscription groups count: 4
Workers count: 5
...
@mensfeld
Copy link
Member

this API needs to be expanded in karafka-testing:

https://github.com/rspec/rspec-rails/blob/main/lib/rspec/rails/matchers/active_job.rb#L233

moving there

@mensfeld mensfeld self-assigned this Apr 21, 2023
@mensfeld mensfeld transferred this issue from karafka/karafka Apr 21, 2023
@mensfeld mensfeld added the enhancement New feature or request label Apr 21, 2023
@mensfeld
Copy link
Member

sorry I forgot about this one. Checking now 🙏

@mensfeld
Copy link
Member

@wahlg when I try to do what you did I am getting:

To use ActiveJob matchers set `ActiveJob::Base.queue_adapter = :test`

any chance you could use this example repo to create a repro? https://github.com/karafka/example-apps/tree/master/v2.1-rails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants