Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Service Bus] Fix test failures in the canary region - part 2 #11597

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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