Skip to content

Commit

Permalink
[Service Bus] Add tests for random scheme in endpoint - track 2 (#8414)
Browse files Browse the repository at this point in the history
* Add tests for random scheme

* coping up with Richard's create* changes
  • Loading branch information
HarshaNalluru authored Apr 30, 2020
1 parent 0552203 commit ea765db
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
66 changes: 64 additions & 2 deletions sdk/servicebus/service-bus/test/serviceBusClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
import { Sender } from "../src/sender";
import { getReceiverClosedErrorMsg } from "../src/util/errors";
import { TestClientType, TestMessage, isMessagingError, checkWithTimeout } from "./utils/testUtils";
import { DispositionType, ReceivedMessageWithLock } from "../src/serviceBusMessage";
import {
DispositionType,
ReceivedMessageWithLock,
ServiceBusMessage
} from "../src/serviceBusMessage";

const should = chai.should();
chai.use(chaiAsPromised);
Expand All @@ -27,7 +31,8 @@ dotenv.config();
import {
createServiceBusClientForTests,
ServiceBusClientForTests,
EntityName
EntityName,
testPeekMsgsLength
} from "./utils/testutils2";

// describe("Create ServiceBusClient and Queue/Topic/Subscription Clients", function(): void {
Expand Down Expand Up @@ -62,6 +67,63 @@ import {
// });
// });

describe("Random scheme in the endpoint from connection string", function(): void {
let sbClient: ServiceBusClientForTests;
let sbClientWithRelaxedEndPoint: ServiceBusClient;
let entities: EntityName;
let senderClient: Sender;
let receiverClient: Receiver<ReceivedMessageWithLock>;

async function beforeEachTest(testClientType: TestClientType) {
sbClient = createServiceBusClientForTests();
entities = await sbClient.test.createTestEntities(testClientType);
await sbClient.close();
sbClientWithRelaxedEndPoint = new ServiceBusClient(
getEnvVars().SERVICEBUS_CONNECTION_STRING.replace("sb://", "CheeseBurger://")
);
senderClient = sbClientWithRelaxedEndPoint.createSender(entities.queue!);
receiverClient = !entities.usesSessions
? sbClientWithRelaxedEndPoint.createReceiver(entities.queue!, "peekLock")
: await sbClientWithRelaxedEndPoint.createSessionReceiver(entities.queue!, "peekLock", {
sessionId: TestMessage.sessionId
});
}

afterEach(async () => {
await senderClient.close();
await receiverClient.close();
await sbClientWithRelaxedEndPoint.close();
});

async function sendReceiveMsg(testMessages: ServiceBusMessage): Promise<void> {
await senderClient.send(testMessages);
await testPeekMsgsLength(receiverClient, 1);

const msgs = await receiverClient.receiveBatch(1);

should.equal(Array.isArray(msgs), true, "`ReceivedMessages` is not an array");
should.equal(msgs.length, 1, "Unexpected number of messages");
should.equal(msgs[0].body, testMessages.body, "MessageBody is different than expected");
should.equal(msgs[0].messageId, testMessages.messageId, "MessageId is different than expected");
should.equal(msgs[0].deliveryCount, 0, "DeliveryCount is different than expected");
await msgs[0].complete();

await testPeekMsgsLength(receiverClient, 0);
}

it("Partitioned Queue: send and receive message", async function(): Promise<void> {
await beforeEachTest(TestClientType.PartitionedQueue);
await sendReceiveMsg(TestMessage.getSample());
});

it("Unpartitioned Queue With Sessions: send and receive message", async function(): Promise<
void
> {
await beforeEachTest(TestClientType.UnpartitionedQueueWithSessions);
await sendReceiveMsg(TestMessage.getSessionSample());
});
});

describe("Errors with non existing Namespace", function(): void {
let sbClient: ServiceBusClient;
let errorWasThrown: boolean;
Expand Down
2 changes: 1 addition & 1 deletion sdk/servicebus/service-bus/test/utils/envVarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let envVars: any;
* Utility to return cached map of environment variables,
* or create and return one from configured values if not existing.
*/
export function getEnvVars(): { [key in EnvVarNames]: any } {
export function getEnvVars(): { [key in EnvVarNames]: string } {
if (envVars != undefined) {
return envVars;
}
Expand Down

0 comments on commit ea765db

Please sign in to comment.