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] Flaky test - filter messages - 1000 iterations #13105

Closed
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
91 changes: 48 additions & 43 deletions sdk/servicebus/service-bus/test/atomRuleFilters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
SqlRuleFilter
} from "../src";
import { ServiceBusAdministrationClient } from "../src/serviceBusAtomManagementClient";
import { sanitizeSerializableObject } from "../src/util/atomXmlHelper";
import { DEFAULT_RULE_NAME } from "../src/util/constants";
import { recreateSubscription, recreateTopic } from "./utils/managementUtils";
import { getConnectionString } from "./utils/testutils2";
Expand All @@ -27,7 +28,7 @@ const serviceBusAtomManagementClient: ServiceBusAdministrationClient = new Servi
getConnectionString()
);

describe("Filter messages with the rules set by the ATOM API", () => {
describe.only("Filter messages with the rules set by the ATOM API", () => {
const topicName = "new-topic";
const subscriptionName = "new-subscription";
const serviceBusClient = new ServiceBusClient(getConnectionString());
Expand All @@ -48,54 +49,58 @@ describe("Filter messages with the rules set by the ATOM API", () => {
numberOfMessagesToBeFiltered: number,
toCheck: (msg: ServiceBusReceivedMessage) => void
) {
await serviceBusAtomManagementClient.createRule(
topicName,
subscriptionName,
"rule-name",
filter
);
try {
const ruleName = "rule-name";
await serviceBusAtomManagementClient.createRule(
topicName,
subscriptionName,
ruleName,
filter
);

await serviceBusClient.createSender(topicName).sendMessages(messagesToSend);
const getRuleResponse = await serviceBusAtomManagementClient.getRule(
topicName,
subscriptionName,
ruleName
);
// Rule filter might have undefined fields, which need to be deleted to match with the created rule
sanitizeSerializableObject(getRuleResponse);
chai.assert.deepEqual(getRuleResponse.filter, filter, "Unexpected filter");

// Making sure the subscription has the expected number of messages
should.equal(
(
await serviceBusAtomManagementClient.getSubscriptionRuntimeProperties(
topicName,
subscriptionName
)
).totalMessageCount,
numberOfMessagesToBeFiltered,
"Unexpected number of messages filtered"
);
await serviceBusClient.createSender(topicName).sendMessages(messagesToSend);

const receivedMessages = await serviceBusClient
.createReceiver(topicName, subscriptionName)
.receiveMessages(5);
should.equal(
receivedMessages.length,
numberOfMessagesToBeFiltered,
"Unexpected number of messages received"
);
const receivedMessages = await serviceBusClient
.createReceiver(topicName, subscriptionName)
.receiveMessages(5);
should.equal(
receivedMessages.length,
numberOfMessagesToBeFiltered,
"Unexpected number of messages received"
);

// Making sure the filtered message is same as the expected one.
toCheck(receivedMessages[0]);
// Making sure the filtered message is same as the expected one.
toCheck(receivedMessages[0]);
} catch (error) {
console.log(error);
}
}

it("subject", async () => {
const subject = "new-subject";
await verifyRuleFilter(
[
{ body: "msg-1", subject }, // to be filtered
{ body: "msg-2" } // not to be filtered
],
{ subject },
1,
(msg) => {
chai.assert.deepEqual(msg.subject, subject, "Unexpected subject on the message");
}
);
});
for (let index = 0; index < 1000; index++) {
it(`subject test - iteration ${index}`, async () => {
const subject = "new-subject";
await verifyRuleFilter(
[
{ body: "msg-1", subject }, // to be filtered
{ body: "msg-2" } // not to be filtered
],
{ subject },
1,
(msg) => {
chai.assert.deepEqual(msg.subject, subject, "Unexpected subject on the message");
}
);
});
}

// TODO: New tests for rule filters to match the sent messages can be added
});