sidekiq-tests
Authors and runs Sidekiq job tests in Ruby - three Sidekiq::Testing modes (`fake!` jobs accumulate in arrays, `inline!` runs jobs immediately, `disable!` enqueues to Redis as normal); RSpec + Minitest helper patterns; clears jobs between tests via `Sidekiq::Worker.clear_all`; assertion patterns on `MyWorker.jobs.size` and `MyWorker.jobs.first[:args]`. Use when the user works with Sidekiq workers and needs unit / integration tests for job enqueueing, scheduling, retry behavior, or unique-job semantics.
Install with skills.sh (any agent)
npx skills add testland/qa --skill sidekiq-testssidekiq-tests
Overview
Sidekiq is the de facto Ruby background-job framework on Redis. The testing model per github.com/sidekiq/sidekiq/wiki/Testing (opens in new window):
Three test modes:
| Mode | Behavior |
|---|---|
Sidekiq::Testing.fake! | "pushes all jobs into a jobs array" (default in test env) |
Sidekiq::Testing.inline! | "run jobs inline" (executes immediately, synchronously) |
Sidekiq::Testing.disable! | "Enqueue jobs to Redis as normal" |
Choose fake! for unit tests (assert enqueueing without execution), inline! for integration tests (test the worker itself end-to-end), disable! for tests that need real Redis (e.g., scheduled-job queries against the Sidekiq API).
When to use
Step 1 - Configure test mode
In spec_helper.rb (RSpec) or test_helper.rb (Minitest):
require 'sidekiq/testing'
Sidekiq::Testing.fake! # default for unit testsSwitch per-test when needed:
it "actually runs the job" do
Sidekiq::Testing.inline! do
create(:order) # triggers OrderConfirmationWorker.perform_async
expect(...).to ...
end
endStep 2 - Clear jobs between tests
Per sk-test (opens in new window), the Minitest helper:
module SidekiqMinitestSupport
def after_teardown
Sidekiq::Worker.clear_all
super
end
endFor RSpec, equivalent:
RSpec.configure do |config|
config.before(:each) { Sidekiq::Worker.clear_all }
endWithout this, jobs accumulate across tests - order-dependent test failures result.
Step 3 - Assert enqueueing (fake! mode)
Per sk-test (opens in new window) (verbatim RSpec example):
expect {
HardWorker.perform_async(1, 2)
}.to change(HardWorker.jobs, :size).by(1)Plus assertion on the basic count: assert_equal 0, HardWorker.jobs.size followed by enqueueing and verifying the count changes.
Inspect job arguments + scheduled time:
HardWorker.perform_in(1.hour, "user-123")
job = HardWorker.jobs.last
expect(job["args"]).to eq(["user-123"])
expect(job["at"]).to be_within(5.seconds).of(1.hour.from_now.to_f)Step 4 - Drain (execute) queued fake! jobs
Without leaving fake! mode, drain executes accumulated jobs:
HardWorker.perform_async(1, 2)
HardWorker.drain # runs all queued HardWorker jobs synchronouslyUseful for integration tests that need fake! globally but selectively run a worker's jobs.
Step 5 - Test scheduled jobs
Per sk-test (opens in new window): "Sidekiq's API does not have a testing mode" - meaning scheduled-set queries always hit Redis, not the test harness. To test scheduled jobs in fake! mode, inspect the job's at field directly (Step 3). For integration testing of the Sidekiq scheduler API, use Sidekiq::Testing.disable! + a real Redis instance (Docker / Testcontainers).
Step 6 - Test retry behavior
Sidekiq retries failed jobs by default (25 retries, exponential backoff). To test retry logic:
it "retries on transient error" do
Sidekiq::Testing.inline!
expect_any_instance_of(HardWorker).to receive(:perform).and_raise(StandardError, "transient")
expect { HardWorker.perform_async }.to raise_error(StandardError)
# In production, Sidekiq would retry; in inline! mode, the raise propagates
endFor more realistic retry testing, switch to disable! + use the Sidekiq API (Sidekiq::RetrySet.new.size) to count retried jobs in Redis.
Step 7 - Test unique-jobs semantics
If using sidekiq-unique-jobs gem, unique-lock state lives in Redis; test in disable! mode against a real Redis instance. fake! mode does NOT enforce uniqueness (jobs all accumulate in the array regardless of unique config).
Step 8 - CI integration
- run: bundle install
- run: bundle exec rspec
# ... or for Minitest:
- run: bundle exec rake testSidekiq tests run in the standard Ruby test runner. For tests that need real Redis, use a service container:
services:
redis:
image: redis:7
ports: [6379:6379]Anti-patterns
| Anti-pattern | Why it fails | Fix |
|---|---|---|
Test code uses inline! everywhere | Slows tests; couples test to worker internals | fake! for enqueue tests; inline! only for integration |
No Sidekiq::Worker.clear_all between tests | Jobs leak across tests; flaky | Add after_teardown / before(:each) hook (Step 2) |
Test scheduled-set via Sidekiq::ScheduledSet.new.size in fake! mode | API hits Redis, not the fake jobs array; returns 0 unexpectedly | Inspect Worker.jobs.last["at"] instead (Step 3) |
| Test unique-jobs in fake! mode | Uniqueness lock isn't enforced; tests pass-by-accident | Use disable! + real Redis (Step 7) |
Limitations
References
Related skills
bullmq-tests
Authors and runs BullMQ job tests in TypeScript / JavaScript - `Queue` and `Worker` patterns, processor mocking, retry/backoff/repeat-job assertions, FlowProducer for parent-child job dependencies, QueueEvents listeners; tests use a real Redis instance (Docker / Testcontainers / `ioredis-mock` for stricter unit-test isolation). Use when the user works with BullMQ in Node.js services and needs unit / integration tests for queue producers, worker processors, or flow orchestration.
celery-tests
Authors and runs Celery task tests in Python - `pytest-celery` fixtures (`celery_app`, `celery_worker` per-test, `celery_session_worker` per-session); `task_always_eager` config NOT recommended for unit tests; `apply()` for synchronous test invocation; mock-and-patch retry patterns via `unittest.mock.patch` on `task.retry`. Use when the user works with Celery task workers and needs unit / integration tests across function-style or class-style tasks.
cron-job-test-author
Build-an-X for cron / scheduler job tests - cron-expression validation patterns (5-field standard `min hour day-month month day-week` + 6-field with seconds + named-list extensions), DST + leap-day edge cases, missed-execution detection (machine downtime catch-up), overlapping-run protection (lock + stale-lock recovery), timezone semantics. Use when authoring tests for cron jobs, Kubernetes CronJobs, BullMQ repeat-jobs, Sidekiq schedulers, or any time-based job runner.
idempotency-test-author
Build-an-X for idempotency tests in any async/job/API context - idempotency-key handling (per Stripe / AWS prescriptive guidance pattern), retry-safe semantics (exactly-once vs at-least-once vs at-most-once), side-effect commutativity verification, fingerprint-based dedup, idempotency-window tuning. Use when authoring tests for any system where the same input could be processed twice (SQS Standard at-least-once, RabbitMQ requeue, retry-on-error logic, webhook redelivery, browser double-click, mobile-network retry).
kafka-consumer-tests
Tests Apache Kafka consumer and producer logic across KafkaJS (Node.js), kafka-go (Go), and Spring Kafka (Java) - spins up a real broker via the Testcontainers Kafka module, asserts offset management and consumer-group rebalance behavior, distinguishes at-least-once from exactly-once (EOS / transactions), validates idempotent producer configuration, and routes unprocessable messages to a dead-letter topic. Use when the user works with Kafka producers or consumers in any language and needs integration or unit tests that exercise delivery semantics, offset commits, rebalance handling, or dead-letter routing.
rabbitmq-tests
Tests RabbitMQ producer/consumer interactions - supports AMQP 0.9.1 and AMQP 1.0 protocols across 6 tutorial patterns (Hello World, Work Queues, Publish/Subscribe, Routing, Topics, RPC) plus Publisher Confirms; consumer ack/nack/requeue patterns; durable queues + persistent messages; quorum vs classic queue; tests via Testcontainers RabbitMQ image or LocalStack-equivalent. Use when the user works with RabbitMQ producers/consumers (pika, amqplib, RabbitMQ.Client, spring-amqp) and needs unit/integration tests.
sqs-tests
Tests AWS SQS queue interactions - Standard (at-least-once delivery, near-unlimited throughput) vs FIFO (exactly-once processing, ordered) queue semantics; visibility-timeout interaction model; dead-letter queue (DLQ) for poison-message isolation; message retention period (default 4 days, configurable 60s - 1209600s); test patterns via LocalStack or `aws-sdk-client-mock` (TypeScript) / `moto` (Python). Use when the user works with AWS SQS producers/consumers and needs unit/integration tests for queue interactions.