Skip to content

Commit ebc4c75

Browse files
committed
Add more tests
1 parent ab9e22a commit ebc4c75

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,73 @@ describe('SnsSqsPermissionConsumer - startupResourcePollingConfig', () => {
220220
expect(consumer.subscriptionProps.topicArn).toBe(topicArn)
221221
expect(consumer.subscriptionProps.queueName).toBe(queueName)
222222
})
223+
224+
it('start() waits for resources and starts consumers (blocking mode)', async () => {
225+
// Create queue first, but not the topic
226+
await assertQueue(sqsClient, { QueueName: queueName })
227+
228+
const consumer = new TestStartupResourcePollingConsumer(diContainer.cradle, {
229+
locatorConfig: {
230+
topicName,
231+
queueUrl,
232+
subscriptionArn:
233+
'arn:aws:sns:eu-west-1:000000000000:dummy:bdf640a2-bedf-475a-98b8-758b88c87395',
234+
startupResourcePolling: {
235+
enabled: true,
236+
pollingIntervalMs: 50,
237+
timeoutMs: 5000,
238+
},
239+
},
240+
creationConfig: {
241+
queue: { QueueName: queueName },
242+
},
243+
})
244+
245+
// Start in background (blocking mode waits for resources)
246+
const startPromise = consumer.start()
247+
248+
// Wait a bit then create the topic
249+
await setTimeout(200)
250+
const topicArn = await assertTopic(snsClient, stsClient, { Name: topicName })
251+
252+
// start() should complete successfully after topic appears
253+
await startPromise
254+
255+
expect(consumer.subscriptionProps.topicArn).toBe(topicArn)
256+
expect(consumer.subscriptionProps.queueUrl).toBe(queueUrl)
257+
258+
// Clean up
259+
await consumer.close()
260+
})
261+
262+
it('start() works immediately when resources already exist (blocking mode)', async () => {
263+
// Create both resources before starting
264+
await assertQueue(sqsClient, { QueueName: queueName })
265+
const topicArn = await assertTopic(snsClient, stsClient, { Name: topicName })
266+
267+
const consumer = new TestStartupResourcePollingConsumer(diContainer.cradle, {
268+
locatorConfig: {
269+
topicArn,
270+
queueUrl,
271+
subscriptionArn:
272+
'arn:aws:sns:eu-west-1:000000000000:dummy:bdf640a2-bedf-475a-98b8-758b88c87395',
273+
startupResourcePolling: {
274+
enabled: true,
275+
pollingIntervalMs: 100,
276+
timeoutMs: 5000,
277+
},
278+
},
279+
})
280+
281+
// start() should complete immediately since resources exist
282+
await consumer.start()
283+
284+
expect(consumer.subscriptionProps.topicArn).toBe(topicArn)
285+
expect(consumer.subscriptionProps.queueUrl).toBe(queueUrl)
286+
287+
// Clean up
288+
await consumer.close()
289+
})
223290
})
224291

225292
describe('when nonBlocking mode is enabled', () => {

0 commit comments

Comments
 (0)