From 10d92c23d3254909969776a3fb35d3a67122f309 Mon Sep 17 00:00:00 2001 From: HarshaNalluru Date: Thu, 1 Oct 2020 13:46:57 -0700 Subject: [PATCH 1/2] Update error message to not have hardcoded value to fix the test in canary region --- sdk/servicebus/service-bus/test/sendBatch.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/servicebus/service-bus/test/sendBatch.spec.ts b/sdk/servicebus/service-bus/test/sendBatch.spec.ts index 1a82be37163c..689c82b8812f 100644 --- a/sdk/servicebus/service-bus/test/sendBatch.spec.ts +++ b/sdk/servicebus/service-bus/test/sendBatch.spec.ts @@ -14,7 +14,7 @@ import { getRandomTestClientTypeWithSessions, getRandomTestClientTypeWithNoSessions } from "./utils/testutils2"; -import { ServiceBusSender } from "../src/sender"; +import { ServiceBusSender, ServiceBusSenderImpl } from "../src/sender"; import { ConditionErrorNameMapper } from "@azure/core-amqp"; describe("Send Batch", () => { @@ -411,9 +411,10 @@ describe("Send Batch", () => { try { await sender.createBatch({ maxSizeInBytes }); } catch (error) { + const maxSize = await (sender as ServiceBusSenderImpl)["_sender"].getMaxMessageSize(); should.equal( error.message, - `Max message size (${maxSizeInBytes} bytes) is greater than maximum message size (262144 bytes) on the AMQP sender link.`, + `Max message size (${maxSizeInBytes} bytes) is greater than maximum message size (${maxSize} bytes) on the AMQP sender link.`, "Unexpected error message when tried to create a batch of size > maximum message size." ); errorIsThrown = true; From 06aa26531ea758adf04a799130f99abbb2fede38 Mon Sep 17 00:00:00 2001 From: HarshaNalluru Date: Thu, 1 Oct 2020 16:23:43 -0700 Subject: [PATCH 2/2] fix canary region test failures --- .../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;