Skip to content

Commit cf023cc

Browse files
committed
Add missing test
1 parent 8970771 commit cf023cc

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

packages/sns/test/consumers/SnsSqsPermissionConsumer.startupResourcePolling.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { SQSClient } from '@aws-sdk/client-sqs'
44
import type { STSClient } from '@aws-sdk/client-sts'
55
import {
66
MessageHandlerConfigBuilder,
7+
NO_TIMEOUT,
78
StartupResourcePollingTimeoutError,
89
} from '@message-queue-toolkit/core'
910
import { assertQueue, deleteQueue } from '@message-queue-toolkit/sqs'
@@ -183,6 +184,41 @@ describe('SnsSqsPermissionConsumer - startupResourcePollingConfig', () => {
183184
// Should throw timeout error since topic never appears
184185
await expect(consumer.init()).rejects.toThrow(StartupResourcePollingTimeoutError)
185186
})
187+
188+
it('polls indefinitely when NO_TIMEOUT is used', async () => {
189+
// Create queue first, but not the topic
190+
await assertQueue(sqsClient, { QueueName: queueName })
191+
192+
const consumer = new TestStartupResourcePollingConsumer(diContainer.cradle, {
193+
locatorConfig: {
194+
topicName,
195+
queueUrl,
196+
subscriptionArn:
197+
'arn:aws:sns:eu-west-1:000000000000:dummy:bdf640a2-bedf-475a-98b8-758b88c87395',
198+
startupResourcePolling: {
199+
enabled: true,
200+
pollingIntervalMs: 50,
201+
timeoutMs: NO_TIMEOUT,
202+
},
203+
},
204+
creationConfig: {
205+
queue: { QueueName: queueName },
206+
},
207+
})
208+
209+
// Start init in background
210+
const initPromise = consumer.init()
211+
212+
// Wait a bit then create the topic
213+
await setTimeout(500)
214+
const topicArn = await assertTopic(snsClient, stsClient, { Name: topicName })
215+
216+
// Init should complete successfully
217+
await initPromise
218+
219+
expect(consumer.subscriptionProps.topicArn).toBe(topicArn)
220+
expect(consumer.subscriptionProps.queueName).toBe(queueName)
221+
})
186222
})
187223

188224
describe('when startupResourcePolling is disabled', () => {

0 commit comments

Comments
 (0)