class Mosquito::TestBackend
 
  - Mosquito::TestBackend
 - Mosquito::Backend
 - Reference
 - Object
 
Overview
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
  Extended Modules
Defined in:
mosquito/test_backend.crClass Method Summary
- .delete(key : String, in ttl : Int64 = 0) : Nil
 - .delete(key : String, in ttl : Time::Span) : Nil
 - .enqueued_jobs
 - .enqueued_jobs=(enqueued_jobs : Array(Mosquito::TestBackend::EnqueuedJob))
 - .expires_in(key : String) : Int64
 - .flush : Nil
 - .flush_enqueued_jobs!
 - .get(key : String, field : String) : String | Nil
 - .increment(key : String, field : String, by value : Int32) : Int64
 - .increment(key : String, field : String) : Int64
 - .list_queues : Array(String)
 - .list_runners : Array(String)
 - .lock?(key : String, value : String, ttl : Time::Span) : Bool
 - .retrieve(key : String) : Hash(String, String)
 - .set(key : String, field : String, value : String) : String
 - .store(key : String, value : Hash(String, String)) : Nil
 - .unlock(key : String, value : String) : Nil
 
Instance Method Summary
- #dequeue : JobRun | Nil
 - #deschedule : Array(JobRun)
 - #dump_dead_q : Array(String)
 - #dump_pending_q : Array(String)
 - #dump_scheduled_q : Array(String)
 - #dump_waiting_q : Array(String)
 - 
        #enqueue(job_run : JobRun) : JobRun
        
          
from queue.cr
 - #finish(job_run : JobRun)
 - #flush : Nil
 - #schedule(job_run : JobRun, at scheduled_time : Time) : JobRun
 - #scheduled_job_run_time(job_run : JobRun) : String | Nil
 - #size(include_dead : Bool = true) : Int64
 - #terminate(job_run : JobRun)
 
Instance methods inherited from class Mosquito::Backend
  
  
    
      build_key(*parts)
    build_key, 
    
  
    
      dead_q
    dead_q, 
    
  
    
      delete(key : String, in ttl = 0) : Nil
    delete, 
    
  
    
      dequeue : JobRun | Nil
    dequeue, 
    
  
    
      deschedule : Array(JobRun)
    deschedule, 
    
  
    
      dump_dead_q : Array(String)
    dump_dead_q, 
    
  
    
      dump_pending_q : Array(String)
    dump_pending_q, 
    
  
    
      dump_scheduled_q : Array(String)
    dump_scheduled_q, 
    
  
    
      dump_waiting_q : Array(String)
    dump_waiting_q, 
    
  
    
      enqueue(job_run : JobRun) : JobRun
    enqueue, 
    
  
    
      expires_in(key : String) : Int64
    expires_in, 
    
  
    
      finish(job_run : JobRun)
    finish, 
    
  
    
      flush : Nil
    flush, 
    
  
    
      pending_q
    pending_q, 
    
  
    
      retrieve(key : String) : Hash(String, String)
    retrieve, 
    
  
    
      schedule(job_run : JobRun, at scheduled_time : Time) : JobRun
    schedule, 
    
  
    
      scheduled_job_run_time(job_run : JobRun) : String | Nil
    scheduled_job_run_time, 
    
  
    
      scheduled_q
    scheduled_q, 
    
  
    
      size(include_dead : Bool = true) : Int64
    size, 
    
  
    
      store(key : String, value : Hash(String, String)) : Nil
    store, 
    
  
    
      terminate(job_run : JobRun)
    terminate, 
    
  
    
      waiting_q
    waiting_q
    
  
    
  Constructor methods inherited from class Mosquito::Backend
  
  
    
      new(name : String | Symbol)
    new
    
  
    
  Class methods inherited from class Mosquito::Backend
  
  
    
      build_key(*parts)
    build_key, 
    
  
    
      named(name)
    named, 
    
  
    
      search_queues
    search_queues
    
  
  
    
    
    
  
    
    
    
  
Class Method Detail
Instance Method Detail
              Description copied from class Mosquito::Backend
            
          
          from queue.cr