breamware / sidekiq-batch

Sidekiq Batch Jobs Implementation
MIT License
357 stars 95 forks source link

RSpec testing and Stats not updating #73

Closed lerxcl closed 1 year ago

lerxcl commented 1 year ago

Here is my block of code:

it "has the jobs completed" do |example|
  b = Sidekiq::Batch.new
  b.jobs do
    3.times {Sidekiq::Worker.perform_async(Time.now.to_i,nil)}
  end
  Sidekiq::Worker.perform_one
  status = Sidekiq::Batch::Status.new(b.bid)
end

Here is my status output: #<Sidekiq::Batch::Status:0x000000010c682808 @bid="4tR00OKDnnKWdA", @completed=0, @failures=0, @pending=3, @props={"created_at"=>"1675329197.732366", "callbacks"=>"{}", "pending"=>"3", "total"=>"3"}, @total=3>

For pending, it is still stuck at 3, where it should have been 2 from perform_one, where it will execute and finish the 1st job in the batch.

I have also used the flag stub_batches: false to use a real Sidekiq Worker to execute these dummy jobs. May I know how is the Status for pending calculated? Thank you!

Meet-Modi commented 9 months ago

Hi, i am facing a similar issue with Rspec in my tests. Do you have any suggestions or guides on how to do it?