mosquito-cr / mosquito

A background task runner for crystal applications supporting periodic (CRON) and manually queued jobs
MIT License
227 stars 24 forks source link

Test Mode #43

Closed adamalbrecht closed 1 year ago

adamalbrecht commented 4 years ago

It would be nice if there were some sort of test mode where I can either just assert that a job was added to the queue or run the jobs immediately when queued.

Here is some information on how this is done in Sidekiq (for ruby): https://github.com/mperham/sidekiq/wiki/Testing

Thanks!

jwoertink commented 3 years ago

For anyone that happens to pop in here, I sort of monkey-patched for my case.

# spec/support/mosquito_helper.cr
module Mosquito
  abstract class QueuedJob < Job
    ENQUEUED_JOBS = [] of String
    def enqueue
      ENQUEUED_JOBS << self.class.name
    end
  end
end

# spec/your_thing_spec.cr

describe "Sending jobs" do
  before_each do
    Mosquito::QueuedJob::ENQUEUED_JOBS.clear
  end

  it "sends a job" do
     MyCode.run
     Mosquito::QueuedJob::ENQUEUED_JOBS.should contain("MyJob")
  end
end

but yes, an official way would be awesome.

robacarp commented 1 year ago

@adamalbrecht @jwoertink if you're still interested, please have a look at #117. Thank you!