class

Mosquito::TestBackend

Inherits Mosquito::Backend < Reference < Object

An in-memory noop backend desigend to be used in application testing.

The test mode backend simply makes a copy of job_runs at enqueue time and holds them in a class getter array.

Job run id, config (aka parameters), and runtime class are kept in memory, and a truncate utility function is provided.

Activate test mode configure the test backend like this:

Mosquito.configure do |settings|
  settings.backend = Mosquito::TestBackend
end

Then in your tests:

describe "testing" do
  it "enqueues the job" do
    # build and enqueue a job
    job_run = EchoJob.new(text: "hello world").enqueue

    # assert that the job was enqueued
    lastest_enqueued_job = Mosquito::TestBackend.enqueued_jobs.last

    # check the job config
    assert_equal "hello world", latest_enqueued_job.config["text"]

    # check the job_id matches
    assert_equal job_run.id, latest_enqueued_job.id

    # optionally, truncate the history
    Mosquito::TestBackend.flush_enqueued_jobs!
  end
end

Class methods

delete(key : String, in ttl : Int64 = 0) : Nil
Source
delete(key : String, in ttl : Time::Span) : Nil
Source
enqueued_jobs
Source
enqueued_jobs=(enqueued_jobs : Array(Mosquito::TestBackend::EnqueuedJob))
Source
expires_in(key : String) : Int64
Source
flush
Source
flush_enqueued_jobs!
Source
get(key : String, field : String) : String | Nil
Source
increment(key : String, field : String, by value : Int32) : Int64
Source
increment(key : String, field : String) : Int64
Source
list_queues
Source
list_runners
Source
lock?(key : String, value : String, ttl : Time::Span) : Bool
Source
retrieve(key : String) : Hash(String, String)
Source
set(key : String, field : String, value : String) : String
Source
store(key : String, value : Hash(String, String)) : Nil
Source
unlock(key : String, value : String) : Nil
Source

Instance methods

dequeue
Source
deschedule
Source
dump_dead_q
Source
dump_pending_q
Source
dump_scheduled_q
Source
dump_waiting_q
Source
enqueue(job_run : JobRun) : JobRun

from queue.cr

Source
finish(job_run : JobRun)
Source
flush
Source
schedule(job_run : JobRun, at scheduled_time : Time) : JobRun
Source
scheduled_job_run_time(job_run : JobRun) : String | Nil
Source
size(include_dead : Bool = true) : Int64
Source
terminate(job_run : JobRun)
Source

Nested types