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.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.crClass Method Summary
- .enqueued_jobs
- .enqueued_jobs=(enqueued_jobs : Array(Mosquito::TestBackend::EnqueuedJob))
- .flush_enqueued_jobs!
Instance Method Summary
- #average(key : String) : Int32
-
#average_push(key : String, value : Int32, window_size : Int32 = 100) : Nil
Metrics
- #delete(key : String, in ttl : Int64 = 0) : Nil
- #delete(key : String, in ttl : Time::Span) : Nil
- #delete_field(key : String, field : String) : Nil
- #deregister_overseer(id : String) : Nil
- #expires_in(key : String) : Int64
- #flush : Nil
- #get(key : String, field : String) : String | Nil
- #increment(key : String, field : String, by value : Int32) : Int64
- #increment(key : String, field : String) : Int64
- #list_active_overseers(since : Time) : Array(String)
- #list_overseers : Array(String)
-
#list_queues : Array(String)
Global
- #lock?(key : String, value : String, ttl : Time::Span) : Bool
- #publish(key : String, value : String) : Nil
- #register_overseer(id : String) : Nil
- #retrieve(key : String) : Hash(String, String)
- #set(key : String, field : String, value : String) : String
- #set(key : String, values : Hash(String, String | Nil) | Hash(String, Nil) | Hash(String, String)) : Nil
- #store(key : String, value : Hash(String, String | Nil) | Hash(String, String)) : Nil
- #subscribe(key : String) : Channel(BroadcastMessage)
-
#unlock(key : String, value : String) : Nil
Coordination
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) : Nildelete(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
Instance Method Detail
def average_push(key : String, value : Int32, window_size : Int32 = 100) : Nil
#
Description copied from class Mosquito::Backend
Metrics
def set(key : String, values : Hash(String, String | Nil) | Hash(String, Nil) | Hash(String, String)) : Nil
#
def unlock(key : String, value : String) : Nil
#
Description copied from class Mosquito::Backend
Coordination