Skip to content

Commit

Permalink
[Service Bus] Update perf tests to use a single sender for all instan…
Browse files Browse the repository at this point in the history
…ces (Azure#14460)

- Imports v7 in the v1 tests to allow creating the resources
- Makes sender static in both v1 and v7
  • Loading branch information
HarshaNalluru authored Mar 30, 2021
1 parent b55ebf8 commit 2e61819
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions sdk/servicebus/service-bus/test/perf/track-1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"license": "ISC",
"dependencies": {
"@azure/service-bus": "^1.1.10",
"@azure/service-bus-v7": "npm:@azure/service-bus@^7.0.3",
"@azure/test-utils-perfstress": "file:../../../../../test-utils/perfstress/azure-test-utils-perfstress-1.0.0.tgz"
},
"scripts": {
Expand Down
17 changes: 11 additions & 6 deletions sdk/servicebus/service-bus/test/perf/track-1/sbBase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@

import { PerfStressTest, getEnvVar } from "@azure/test-utils-perfstress";
import { ServiceBusClient } from "@azure/service-bus";
import { ServiceBusAdministrationClient } from "@azure/service-bus-v7";

// Expects the .env file at the same level as the "test" folder
import * as dotenv from "dotenv";
dotenv.config({ path: "../../../.env" });

const connectionString = getEnvVar("SERVICEBUS_CONNECTION_STRING");
const sbClient = ServiceBusClient.createFromConnectionString(connectionString);

export abstract class ServiceBusTest<TOptions> extends PerfStressTest<TOptions> {
sbClient: ServiceBusClient;
static queueName = getEnvVar("QUEUE_NAME");
static sbClient: ServiceBusClient = ServiceBusClient.createFromConnectionString(connectionString);
static sbAdminClient = new ServiceBusAdministrationClient(connectionString);
static queueName = `newqueue-${Math.ceil(Math.random() * 1000)}`;

constructor() {
super();
this.sbClient = sbClient;
}

public async globalCleanup() {
await this.sbClient.close();
public async globalSetup(): Promise<void> {
await ServiceBusTest.sbAdminClient.createQueue(ServiceBusTest.queueName);
}

public async globalCleanup(): Promise<void> {
await ServiceBusTest.sbClient.close();
await ServiceBusTest.sbAdminClient.deleteQueue(ServiceBusTest.queueName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface SendTestOptions {
}

export class BatchSendTest extends ServiceBusTest<SendTestOptions> {
sender: Sender;
static sender = ServiceBusTest.sbClient.createQueueClient(BatchSendTest.queueName).createSender();
batch: SendableMessageInfo[];
public options: PerfStressOptionDictionary<SendTestOptions> = {
messageBodySize: {
Expand All @@ -32,14 +32,13 @@ export class BatchSendTest extends ServiceBusTest<SendTestOptions> {

constructor() {
super();
this.sender = this.sbClient.createQueueClient(BatchSendTest.queueName).createSender();
const sbMessage = {
body: Buffer.alloc(this.parsedOptions.messageBodySize.value!)
};
this.batch = new Array(this.parsedOptions.numberOfMessages.value!).fill(sbMessage);
}

async runAsync(): Promise<void> {
await this.sender.sendBatch(this.batch);
await BatchSendTest.sender.sendBatch(this.batch);
}
}
3 changes: 1 addition & 2 deletions sdk/servicebus/service-bus/test/perf/track-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
3. Create a service-bus namespace and populate the .env file at `servicebus\service-bus` folder with `SERVICEBUS_CONNECTION_STRING` variables.
4. Run the tests as follows

- simple send
- `npm run perf-test:node -- SimpleSendTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
- batch send
- `npm run perf-test:node -- BatchSendTest --warmup 2 --duration 7 --parallel 2`
- `npm run perf-test:node -- BatchSendTest --warmup 1 --duration 25 --iterations 2 --parallel 32 --messageBodySize 10240 --numberOfMessages 10`
6 changes: 2 additions & 4 deletions sdk/servicebus/service-bus/test/perf/track-2/sbBase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@ import * as dotenv from "dotenv";
dotenv.config();

const connectionString = getEnvVar("SERVICEBUS_CONNECTION_STRING");
const sbClient = new ServiceBusClient(connectionString);

export abstract class ServiceBusTest<TOptions> extends PerfStressTest<TOptions> {
sbClient: ServiceBusClient;
static sbClient: ServiceBusClient = new ServiceBusClient(connectionString);
static sbAdminClient = new ServiceBusAdministrationClient(connectionString);
static queueName = `newqueue-${Math.ceil(Math.random() * 1000)}`;

constructor() {
super();
this.sbClient = sbClient;
}

public async globalSetup(): Promise<void> {
await ServiceBusTest.sbAdminClient.createQueue(ServiceBusTest.queueName);
}

public async globalCleanup(): Promise<void> {
await ServiceBusTest.sbClient.close();
await ServiceBusTest.sbAdminClient.deleteQueue(ServiceBusTest.queueName);
await this.sbClient.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface SendTestOptions {
}

export class BatchSendTest extends ServiceBusTest<SendTestOptions> {
sender: ServiceBusSender;
static sender: ServiceBusSender = ServiceBusTest.sbClient.createSender(BatchSendTest.queueName);
batch: ServiceBusMessage[];
public options: PerfStressOptionDictionary<SendTestOptions> = {
messageBodySize: {
Expand All @@ -32,14 +32,13 @@ export class BatchSendTest extends ServiceBusTest<SendTestOptions> {

constructor() {
super();
this.sender = this.sbClient.createSender(BatchSendTest.queueName);
const sbMessage = {
body: Buffer.alloc(this.parsedOptions.messageBodySize.value!)
};
this.batch = new Array(this.parsedOptions.numberOfMessages.value!).fill(sbMessage);
}

async runAsync(): Promise<void> {
await this.sender.sendMessages(this.batch);
await BatchSendTest.sender.sendMessages(this.batch);
}
}

0 comments on commit 2e61819

Please sign in to comment.