Skip to content

Commit

Permalink
[Service Bus] Fix test failures in the canary region - part 2 (#11597)
Browse files Browse the repository at this point in the history
From #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 #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.
  • Loading branch information
HarshaNalluru authored Oct 2, 2020
1 parent f962338 commit a6f5b4f
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions sdk/servicebus/service-bus/test/sendBatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
// 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;
Expand Down

0 comments on commit a6f5b4f

Please sign in to comment.