statianzo / que-testing

Make assertions on enqueued jobs
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

Enqueued job is immediately destroyed #4

Closed lessless closed 7 years ago

lessless commented 7 years ago

Hello,

I have simple test to check if job was scheduled or not, but it fails because of queue is empty

 it "runs job immediately if it scheduled between 16:00 and 17:30" do
      [DateTime.now.change(hour: 16), DateTime.now.change(hour: 17, min: 30)].each_with_index do |moment, i|
        Timecop.freeze(moment) do
          described_class.new(channel).today
          expect(jobs.["i"]["run_at"]).to eq(moment)
        end
      end

The job is put in a queue like this: PublicationJob.enqueue channel_name, @channel.id and returns following: <PublicationJob:0x007fbb11bd7080 @attrs={:args=>[channel_name, 3]}, @destroyed=true>

statianzo commented 7 years ago

Any jobs you create will be PublicationJob.jobs until PublicationJob.jobs.clear is called.

I'm going to guess that you intended to use i instead of "i". Try making this change

- expect(jobs.["i"]["run_at"]).to eq(moment)
+ expect(jobs[i]["run_at"]).to eq(moment)
lessless commented 7 years ago

The "i" was my mistake indeed, but the queue is empty http://d.pr/i/SKcp

statianzo commented 7 years ago

A couple more questions. What type is described_class and what is the logic of today? Does it include a call to PublicationJob.enqueue?

lessless commented 7 years ago

described_class is referencing Scheduler object

RSpec.describe Scheduler do
end

Its #run is nearly following:

  def today(hour: DEFAULT_HOUR, minute: DEFAULT_MINUTE)
      PublicationJob.enqueue channel_kind, @channel.id, run_at: DateTime.now.change(hour: hour, min: minute)     
  end

and as you can see on the screenshot it returns PublicationJob with instance variable @destroyed set to true

statianzo commented 7 years ago

What is Que.mode set to? The behavior seems like Que.mode is :sync. :sync skips the adapter (the hook that que-testing uses). Make sure Que.mode is set to :off.

lessless commented 7 years ago

Indeed, that was the cause of the "problem". My apologies for polluting the tracker!