From a6f5b4fb1a69e1b7c4aece7f6b25779efccb3f17 Mon Sep 17 00:00:00 2001 From: Harsha Nalluru Date: Thu, 1 Oct 2020 17:12:51 -0700 Subject: [PATCH] [Service Bus] Fix test failures in the canary region - part 2 (#11597) From https://github.com/Azure/azure-sdk-for-js/pull/11576 ![image](https://user-images.githubusercontent.com/10452642/94872905-b18a2b00-0402-11eb-8339-8818586a594a.png) ### Background We realized the max message size on the link has been increased with https://github.com/Azure/azure-sdk-for-js/pull/11588. ### Cause The new test failures were caused since the messages that can be held/sent are have been increased through the new limit, more many messages being sent would mean that we'd receive all of them and verify per the test which would take more time and hence the timeouts. ### Fix in the test Increase the message size and also create messages based on the maxMessageSize. This brings down the test time and would also be mindful of the potential size increase in the future. --- .../service-bus/test/sendBatch.spec.ts | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/sdk/servicebus/service-bus/test/sendBatch.spec.ts b/sdk/servicebus/service-bus/test/sendBatch.spec.ts index 689c82b8812f..9c4b28b117d9 100644 --- a/sdk/servicebus/service-bus/test/sendBatch.spec.ts +++ b/sdk/servicebus/service-bus/test/sendBatch.spec.ts @@ -100,29 +100,25 @@ describe("Send Batch", () => { await afterEachTest(); }); - function prepareMessages(useSessions: boolean): ServiceBusMessage[] { - const messagesToSend: ServiceBusMessage[] = []; - for (let i = 0; i < 1000; i++) { - messagesToSend.push({ - body: Buffer.alloc(2000), - messageId: `message ${i}`, - sessionId: useSessions ? `someSession ${i}` : undefined, - partitionKey: useSessions ? `someSession ${i}` : undefined - }); - } - return messagesToSend; - } - async function testSendBatch( // Max batch size maxSizeInBytes?: number ): Promise { // Prepare messages to send - const messagesToSend = prepareMessages(entityNames.usesSessions); const sentMessages: ServiceBusMessage[] = []; const batchMessage = await sender.createBatch({ maxSizeInBytes }); - for (const messageToSend of messagesToSend) { + // Size of each message will be > 20000 bytes, maxMessageSize/20000 would exceed the limit + const numberOfMessagesToSend = + (await (sender as ServiceBusSenderImpl)["_sender"].getMaxMessageSize()) / 20000; + + for (let i = 0; i < numberOfMessagesToSend; i++) { + const messageToSend = { + body: Buffer.alloc(20000), + messageId: `message ${i}`, + sessionId: entityNames.usesSessions ? `someSession ${i}` : undefined, + partitionKey: entityNames.usesSessions ? `someSession ${i}` : undefined + }; const batchHasCapacity = batchMessage.tryAdd(messageToSend); if (!batchHasCapacity) { break;