# 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 1. **Simple Job Processing**: Adds a basic job and verifies it completes successfully 2. **Delayed Job Processing**: Tests jobs that take longer to process 3. **Error Handling**: Verifies that failed jobs are properly handled ### How It Works The test script: 1. Connects to Redis (default: `redis://:queue_dev_password@localhost:6388`) 2. Creates jobs in the `test` queue 3. The queue worker picks up these jobs 4. Jobs are delegated to the health controller's `/internal/process-job` endpoint 5. The test script polls for job completion 6. Reports success/failure for each test ### Prerequisites Before running the test: 1. **Redis must be running**: ```bash # Default config: localhost:6388 with password "queue_dev_password" redis-server --port 6388 --requirepass queue_dev_password ``` 2. **Queue worker must be running**: ```bash npm run start:dev # or npm run start ``` ### Running the Test ```bash # 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: ```typescript // 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 to `true` to simulate a failure - `delayMs`: Number of milliseconds to delay before completing - Any other fields are echoed back in the result