@@ -9,8 +9,6 @@ import type { Dependencies } from '../utils/testContext.ts'
99import { registerDependencies } from '../utils/testContext.ts'
1010import { SnsSqsPermissionConsumer } from './SnsSqsPermissionConsumer.ts'
1111
12- const isLocalstack = process . env . QUEUE_BACKEND === 'localstack'
13-
1412describe ( 'SnsSqsPermissionConsumer - subscription dead letter queue' , ( ) => {
1513 const topicName = 'subscription-dlq-test-topic'
1614 const queueName = 'subscription-dlq-test-queue'
@@ -108,70 +106,62 @@ describe('SnsSqsPermissionConsumer - subscription dead letter queue', () => {
108106 expect ( subscriptionAttributes . result ?. attributes ?. RedrivePolicy ) . toBeUndefined ( )
109107 } )
110108
111- // Real delivery-failure routing depends on the SNS broker honoring the
112- // subscription RedrivePolicy. fauxqs silently drops messages when the
113- // endpoint queue is missing (see fanOutToSubscriptions: `if (!queue) continue`),
114- // so this only runs against LocalStack.
115- it . skipIf ( ! isLocalstack ) (
116- 'routes undeliverable messages to the consumer DLQ when the endpoint queue is gone' ,
117- async ( ) => {
118- consumer = new SnsSqsPermissionConsumer ( diContainer . cradle , {
119- creationConfig : {
120- topic : { Name : topicName } ,
121- queue : { QueueName : queueName } ,
122- } ,
123- deadLetterQueue : {
124- redrivePolicy : { maxReceiveCount : 3 } ,
125- creationConfig : { queue : { QueueName : deadLetterQueueName } } ,
126- } ,
127- subscriptionDeadLetterQueue : { reuseConsumerDeadLetterQueue : true } ,
128- } )
129-
130- await consumer . init ( )
131-
132- const {
133- topicArn,
134- queueName : sourceQueueName ,
135- deadLetterQueueUrl,
136- } = consumer . subscriptionProps
137-
138- // Force a delivery failure: delete the endpoint queue while the
139- // subscription stays in place. Subsequent SNS publishes can't reach it,
140- // so the subscription RedrivePolicy should route the message to the DLQ.
141- await testAdmin . deleteQueues ( sourceQueueName ! )
142-
143- await snsClient . send (
144- new PublishCommand ( {
145- TopicArn : topicArn ,
146- Message : JSON . stringify ( {
147- id : 'sub-dlq-1' ,
148- messageType : 'remove' ,
149- timestamp : new Date ( ) . toISOString ( ) ,
150- } ) ,
109+ it ( 'routes undeliverable messages to the consumer DLQ when the endpoint queue is gone' , async ( ) => {
110+ consumer = new SnsSqsPermissionConsumer ( diContainer . cradle , {
111+ creationConfig : {
112+ topic : { Name : topicName } ,
113+ queue : { QueueName : queueName } ,
114+ } ,
115+ deadLetterQueue : {
116+ redrivePolicy : { maxReceiveCount : 3 } ,
117+ creationConfig : { queue : { QueueName : deadLetterQueueName } } ,
118+ } ,
119+ subscriptionDeadLetterQueue : { reuseConsumerDeadLetterQueue : true } ,
120+ } )
121+
122+ await consumer . init ( )
123+
124+ const {
125+ topicArn,
126+ queueName : sourceQueueName ,
127+ deadLetterQueueUrl,
128+ } = consumer . subscriptionProps
129+
130+ // Force a delivery failure: delete the endpoint queue while the
131+ // subscription stays in place. Subsequent SNS publishes can't reach it,
132+ // so the subscription RedrivePolicy should route the message to the DLQ.
133+ await testAdmin . deleteQueues ( sourceQueueName ! )
134+
135+ await snsClient . send (
136+ new PublishCommand ( {
137+ TopicArn : topicArn ,
138+ Message : JSON . stringify ( {
139+ id : 'sub-dlq-1' ,
140+ messageType : 'remove' ,
141+ timestamp : new Date ( ) . toISOString ( ) ,
151142 } ) ,
152- )
153-
154- let dlqBody : string | undefined
155- const arrived = await waitAndRetry (
156- async ( ) => {
157- const response = await sqsClient . send (
158- new ReceiveMessageCommand ( {
159- QueueUrl : deadLetterQueueUrl ,
160- MaxNumberOfMessages : 1 ,
161- WaitTimeSeconds : 1 ,
162- } ) ,
163- )
164- dlqBody = response . Messages ?. [ 0 ] ?. Body
165- return ! ! dlqBody
166- } ,
167- 500 ,
168- 40 ,
169- )
170-
171- expect ( arrived ) . toBe ( true )
172- expect ( dlqBody ) . toContain ( 'sub-dlq-1' )
173- } ,
174- 60_000 ,
175- )
143+ } ) ,
144+ )
145+
146+ let dlqBody : string | undefined
147+ const arrived = await waitAndRetry (
148+ async ( ) => {
149+ const response = await sqsClient . send (
150+ new ReceiveMessageCommand ( {
151+ QueueUrl : deadLetterQueueUrl ,
152+ MaxNumberOfMessages : 1 ,
153+ WaitTimeSeconds : 1 ,
154+ } ) ,
155+ )
156+ dlqBody = response . Messages ?. [ 0 ] ?. Body
157+ return ! ! dlqBody
158+ } ,
159+ 50 ,
160+ 60 ,
161+ )
162+
163+ expect ( arrived ) . toBe ( true )
164+ expect ( dlqBody ) . toContain ( 'sub-dlq-1' )
165+ } )
176166 } )
177167} )
0 commit comments