class Mosquito::TestBackend

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.new
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

Defined in:

mosquito/test_backend.cr

Class Method Summary

Instance Method Summary

Instance methods inherited from class Mosquito::Backend

average(key : String) : Int32 average, average_push(key : String, value : Int32, window_size : Int32 = 100) : Nil average_push, build_key(*parts) build_key, delete(key : String, in ttl : Int64 = 0) : Nil
delete(key : String, in ttl : Time::Span) : Nil
delete
, delete_field(key : String, field : String) : Nil delete_field, deregister_overseer(id : String) : Nil deregister_overseer, expires_in(key : String) : Int64 expires_in, flush : Nil flush, get(key : String, field : String) : String | Nil get, increment(key : String, field : String, by value : Int32) : Int64
increment(key : String, field : String) : Int64
increment
, list_active_overseers(since : Time) : Array(String) list_active_overseers, list_overseers : Array(String) list_overseers, list_queues : Array(String) list_queues, lock?(key : String, value : String, ttl : Time::Span) : Bool lock?, publish(key : String, value : String) : Nil publish, queue(name : String | Symbol) : Queue queue, register_overseer(id : String) : Nil register_overseer, retrieve(key : String) : Hash(String, String) retrieve, set(key : String, field : String, value : String) : String
set(key : String, values : Hash(String, String | Nil) | Hash(String, Nil) | Hash(String, String)) : Nil
set
, store(key : String, value : Hash(String, String | Nil) | Hash(String, String)) : Nil store, subscribe(key : String) : Channel(BroadcastMessage) subscribe, unlock(key : String, value : String) : Nil unlock

Class Method Detail

def self.enqueued_jobs #

def self.enqueued_jobs=(enqueued_jobs : Array(Mosquito::TestBackend::EnqueuedJob)) #

def self.flush_enqueued_jobs! #

Instance Method Detail

def average(key : String) : Int32 #

def average_push(key : String, value : Int32, window_size : Int32 = 100) : Nil #
Description copied from class Mosquito::Backend

Metrics


def delete(key : String, in ttl : Int64 = 0) : Nil #

def delete(key : String, in ttl : Time::Span) : Nil #

def delete_field(key : String, field : String) : Nil #

def deregister_overseer(id : String) : Nil #

def expires_in(key : String) : Int64 #

def flush : Nil #

def get(key : String, field : String) : String | Nil #

def increment(key : String, field : String, by value : Int32) : Int64 #

def increment(key : String, field : String) : Int64 #

def list_active_overseers(since : Time) : Array(String) #

def list_overseers : Array(String) #

def list_queues : Array(String) #
Description copied from class Mosquito::Backend

Global


def lock?(key : String, value : String, ttl : Time::Span) : Bool #

def publish(key : String, value : String) : Nil #

def register_overseer(id : String) : Nil #

def retrieve(key : String) : Hash(String, String) #

def set(key : String, field : String, value : String) : String #

def set(key : String, values : Hash(String, String | Nil) | Hash(String, Nil) | Hash(String, String)) : Nil #

def store(key : String, value : Hash(String, String | Nil) | Hash(String, String)) : Nil #

def subscribe(key : String) : Channel(BroadcastMessage) #

def unlock(key : String, value : String) : Nil #
Description copied from class Mosquito::Backend

Coordination