Giter Site home page Giter Site logo

Comments (8)

kmayer avatar kmayer commented on July 30, 2024 8

Here's how we do it at PacerPro:

We modified the worker so it returns a Sidekiq::Batch object:

class BatchSearch
  include Sidekiq::Worker

  def perform(search_id)
    @search = Search.find(search_id)

    Sidekiq::Batch.new.tap do |batch|
      batch.on(:complete, Callback, {'search_id' => search_id})
      batch.jobs do
        @search.end_points.each do |court|
          SearchWorker.perform_async(court.id, @search.id, jid)
        end
      end
    end
  end
end

and in RSpec, we call #perform to run synchronously, then batch.status.join to run the callbacks and check behavior.

      it 'changes the state of the search to "finished"' do
        expect {
          batch = worker.perform(search.id)
          batch.status.join
        }.to change { search.reload.status }.from("searching").to("finished")
      end

from rspec-sidekiq.

scifisamurai avatar scifisamurai commented on July 30, 2024 2

I'm also curious about this. Any suggestions?

from rspec-sidekiq.

kmayer avatar kmayer commented on July 30, 2024 1

from rspec-sidekiq.

packrat386 avatar packrat386 commented on July 30, 2024 1

I mean, PRs are welcome, but I feel reasonably confident in speaking for the team that we're not going to to spend time working on it if it's a feature that perham thinks is unlikely to work well.

from rspec-sidekiq.

benoittgt avatar benoittgt commented on July 30, 2024

First thanks @kmayer for the job already done.
I have the same problem. From this discussion, Mike Perham say:

I don't support automated testing batches in-process. You can test your worker code, you can test your callback code. You cannot test the entire workflow. People have hacked together solutions but nothing that I want to support long-term.

But I would like to know if rspec-sidekiq plan to add more support for batch callbacks.

from rspec-sidekiq.

benoittgt avatar benoittgt commented on July 30, 2024

Sorry for the bump @kmayer. But I'm still interested ;)

from rspec-sidekiq.

packrat386 avatar packrat386 commented on July 30, 2024

If mike perham is against it we're probably not going to add it.

from rspec-sidekiq.

benoittgt avatar benoittgt commented on July 30, 2024

He said "If anyone comes up with a solution they think is useful to all Sidekiq Pro users, I'm happy to review"

from rspec-sidekiq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.