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.
Install with skills.sh (any agent)
npx skills add testland/qa --skill sqs-testssqs-tests
Overview
Two queue types, per the SQS developer guide (opens in new window):
| Type | Delivery semantics |
|---|---|
| Standard | "at-least-once message delivery" |
| FIFO | "exactly-once message processing" + "high-throughput" mode |
The semantic difference cascades through every test pattern: a Standard-queue test must assume duplicates can occur; a FIFO test must assume strict ordering.
When to use
Step 1 - Test approach: mock vs LocalStack vs real
Three approaches, ordered by isolation:
| Approach | Pros | Cons |
|---|---|---|
aws-sdk-client-mock (TS) / moto (Python) | Pure unit, no network | Doesn't catch AWS-side behavior (visibility timeouts, DLQ routing) |
| LocalStack (Docker SQS emulator) | Full SQS semantics locally | Slower; not 100% behavior parity with AWS SQS |
| Real SQS in sandbox AWS account | Highest fidelity | Costs money; per-PR queue cleanup needed |
For pure logic tests (does the code call SendMessage with the right body?), use mocks. For semantic tests (does retry-on-failure work end-to-end?), use LocalStack. For pre-prod smoke, use real SQS.
Step 2 - Mock-based unit test (TypeScript)
import { mockClient } from 'aws-sdk-client-mock';
import { SQSClient, SendMessageCommand } from '@aws-sdk/client-sqs';
const sqsMock = mockClient(SQSClient);
beforeEach(() => sqsMock.reset());
it('sends order-placed message to SQS', async () => {
sqsMock.on(SendMessageCommand).resolves({ MessageId: 'msg-123' });
await placeOrder({ customerId: 1 });
expect(sqsMock.commandCalls(SendMessageCommand)).toHaveLength(1);
expect(sqsMock.commandCalls(SendMessageCommand)[0].args[0].input).toMatchObject({
QueueUrl: expect.stringContaining('orders'),
MessageBody: expect.stringContaining('"customerId":1'),
});
});Step 3 - Mock-based unit test (Python)
import boto3
from moto import mock_aws
@mock_aws
def test_send_order_message():
sqs = boto3.client('sqs', region_name='us-east-1')
queue_url = sqs.create_queue(QueueName='orders')['QueueUrl']
place_order(customer_id=1)
response = sqs.receive_message(QueueUrl=queue_url, MaxNumberOfMessages=10)
assert len(response['Messages']) == 1
body = json.loads(response['Messages'][0]['Body'])
assert body['customerId'] == 1moto's @mock_aws decorator intercepts boto3 SQS calls; tests run without network.
Step 4 - LocalStack integration test
# docker-compose.yml
services:
localstack:
image: localstack/localstack:latest
ports: [4566:4566]
environment:
SERVICES: sqssqs = boto3.client(
'sqs',
endpoint_url='http://localhost:4566',
region_name='us-east-1',
aws_access_key_id='test', aws_secret_access_key='test',
)
queue_url = sqs.create_queue(QueueName='orders')['QueueUrl']
# ... full SQS API works, including visibility timeouts, DLQ, FIFOStep 5 - Test visibility-timeout behavior
Visibility timeout keeps an in-flight message invisible to other receivers for a configurable window, preventing duplicate processing (SQS developer guide (opens in new window)).
Test pattern (LocalStack or real SQS, NOT mock):
sqs.send_message(QueueUrl=queue_url, MessageBody='test')
msg1 = sqs.receive_message(QueueUrl=queue_url, VisibilityTimeout=30)['Messages'][0]
# Within 30s, the message should be invisible to other receivers:
msg2 = sqs.receive_message(QueueUrl=queue_url)
assert msg2.get('Messages') is None
# After visibility timeout (or explicit ChangeMessageVisibility), it returns:
sqs.change_message_visibility(
QueueUrl=queue_url,
ReceiptHandle=msg1['ReceiptHandle'],
VisibilityTimeout=0,
)
msg3 = sqs.receive_message(QueueUrl=queue_url)
assert msg3['Messages'][0]['MessageId'] == msg1['MessageId']Step 6 - Test DLQ routing
SQS routes a message to the dead-letter queue after maxReceiveCount failed deliveries (poison-message isolation, per the SQS developer guide). Full LocalStack recipe: references/localstack-recipes.md.
Step 7 - Test FIFO ordering + dedup
FIFO queues (FifoQueue: 'true') preserve per-MessageGroupId order and drop identical bodies within a 5-minute dedup window (ContentBasedDeduplication). Full LocalStack recipe: references/localstack-recipes.md.
Step 8 - Message retention
SQS auto-deletes messages older than the retention period: default 4 days, configurable from 60 seconds to 1,209,600 seconds (14 days) (SQS developer guide (opens in new window)). Tests rarely verify retention directly; document the expected retention in queue setup (Terraform / CloudFormation) and review per-team.
Step 9 - CI integration
services:
localstack:
image: localstack/localstack:latest
ports: [4566:4566]
env: { SERVICES: sqs }
steps:
- run: pytest tests/integration/sqs/ -vAnti-patterns
| Anti-pattern | Why it fails | Fix |
|---|---|---|
| Test visibility-timeout via mock | Mock doesn't track invisibility window; tests pass-by-accident | Use LocalStack (Step 4 - 5) |
| Skip DLQ-routing test | Poison-message handling unverified; production incidents | Always cover DLQ for production queues (Step 6) |
| Use Standard-queue body assertions sensitive to delivery order | At-least-once = duplicates + reordering | Assert per-message processing idempotency, not order |
| Hard-code queue URLs in tests | Tests break when account / region changes | Pull from env vars / fixtures |
Limitations
References
SQS LocalStack recipes: DLQ routing and FIFO ordering
View source (opens in new window)SQS LocalStack recipes: DLQ routing and FIFO ordering
DLQ-routing and FIFO ordering/dedup recipes referenced from sqs-tests's SKILL.md (Step 6 and Step 7). Both run against LocalStack (or real SQS), not mocks. The mock-based unit tests and the visibility-timeout recipe stay in the main skill file.
DLQ routing
SQS supports dead-letter queues for poison-message isolation; after maxReceiveCount failed deliveries the message moves to the DLQ (per the SQS developer guide).
dlq_url = sqs.create_queue(QueueName='orders-dlq')['QueueUrl']
dlq_arn = sqs.get_queue_attributes(QueueUrl=dlq_url, AttributeNames=['QueueArn'])['Attributes']['QueueArn']
queue_url = sqs.create_queue(
QueueName='orders',
Attributes={
'RedrivePolicy': json.dumps({'deadLetterTargetArn': dlq_arn, 'maxReceiveCount': 3}),
},
)['QueueUrl']
sqs.send_message(QueueUrl=queue_url, MessageBody='poison')
for _ in range(4):
msg = sqs.receive_message(QueueUrl=queue_url, VisibilityTimeout=0)
# Don't delete; let visibility expire and re-receive
# After 3 receives, message is in DLQ:
dlq_msg = sqs.receive_message(QueueUrl=dlq_url)
assert dlq_msg['Messages'][0]['Body'] == 'poison'FIFO ordering + dedup
fifo_url = sqs.create_queue(
QueueName='orders.fifo',
Attributes={'FifoQueue': 'true', 'ContentBasedDeduplication': 'true'},
)['QueueUrl']
sqs.send_message(QueueUrl=fifo_url, MessageBody='msg-1', MessageGroupId='group-A')
sqs.send_message(QueueUrl=fifo_url, MessageBody='msg-2', MessageGroupId='group-A')
# Same body within 5min dedup window -> second send is dropped:
sqs.send_message(QueueUrl=fifo_url, MessageBody='msg-1', MessageGroupId='group-A')
response = sqs.receive_message(QueueUrl=fifo_url, MaxNumberOfMessages=10)
bodies = [m['Body'] for m in response['Messages']]
assert bodies == ['msg-1', 'msg-2'] # Strict order; dedup appliedRelated 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.
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.