|
…
|
||
|---|---|---|
| .. | ||
| README.md | ||
| test-queue.ts | ||
| verify-setup.sh | ||
Queue Worker Test Scripts
This directory contains test scripts for the queue worker service.
test-queue.ts
End-to-end test script that verifies the complete queue processing pipeline.
What It Tests
- Simple Job Processing: Adds a basic job and verifies it completes successfully
- Delayed Job Processing: Tests jobs that take longer to process
- Error Handling: Verifies that failed jobs are properly handled
How It Works
The test script:
- Connects to Redis (default:
redis://:queue_dev_password@localhost:6388) - Creates jobs in the
testqueue - The queue worker picks up these jobs
- Jobs are delegated to the health controller's
/internal/process-jobendpoint - The test script polls for job completion
- Reports success/failure for each test
Prerequisites
Before running the test:
-
Redis must be running:
# Default config: localhost:6388 with password "queue_dev_password" redis-server --port 6388 --requirepass queue_dev_password -
Queue worker must be running:
npm run start:dev # or npm run start
Running the Test
# Default (uses redis://:queue_dev_password@localhost:6388)
npm test
# Custom Redis URL
REDIS_URL=redis://:mypassword@localhost:6379 npm test
Expected Output
🔌 Connecting to Redis...
✅ Redis connection successful
🧪 Running queue worker tests...
Test 1: Simple successful job
Added job 1
✅ Job completed in 234ms
Result: {
"jobId": "1",
"jobName": "test-job",
"attemptsMade": 0,
"processedAt": "2024-01-02T22:00:00.000Z",
"echo": {
"testId": "test-1",
"message": "Hello, queue worker!"
}
}
Test 2: Job with delay
Added job 2
✅ Job completed in 1156ms
Test 3: Intentional failure (should fail)
Added job 3
✅ Job failed as expected in 89ms
Error: Intentional test failure
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📊 Test Summary
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total tests: 3
✅ Completed: 2
❌ Failed: 1
⏱️ Timeout: 0
🎉 All tests passed!
Test Architecture
┌─────────────┐
│ test-queue │ 1. Adds jobs to Redis
│ script │
└──────┬──────┘
│
▼
┌─────────────┐
│ Redis │ 2. Stores jobs
│ (port 6388)│
└──────┬──────┘
│
▼
┌─────────────┐
│ Queue │ 3. Picks up jobs from test queue
│ Worker │
└──────┬──────┘
│
▼ HTTP POST to /internal/process-job
┌─────────────┐
│ Health │ 4. Processes test jobs (success/fail/delay)
│ Controller │
└──────┬──────┘
│
▼
┌─────────────┐
│ test-queue │ 5. Polls for job completion
│ script │
└─────────────┘
Test Queue Details
The test queue is a special internal queue:
- Queue name:
test - Owner:
internal/health - Endpoint: Health controller at
http://localhost:3080/internal/process-job - Job types:
test-job - Configuration:
- Concurrency: 5
- Attempts: 3
- Backoff: Fixed 1 second
- Timeout: 10 seconds
- Remove on complete: true (auto-cleanup)
Customizing Tests
Edit test-queue.ts to add more test scenarios:
// Add a new test
const jobId = await this.addJob({
testId: 'test-4',
message: 'Custom test',
shouldFail: false,
delayMs: 500,
});
The health controller supports these job data fields:
shouldFail: Set totrueto simulate a failuredelayMs: Number of milliseconds to delay before completing- Any other fields are echoed back in the result