Skip to content

Commit

Permalink
Test for error on connection.close() bubbling up (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a authored Jul 28, 2020
1 parent 86cad30 commit 7237cf8
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions test/connection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("Connection", () => {
})();
});

it("connectionError", (done: Function) => {
it("connectionError on connection open", (done: Function) => {
const errorCondition = "amqp:connection:forced";
const errorDescription = "testing error on close";
mockService.on(
Expand Down Expand Up @@ -98,7 +98,7 @@ describe("Connection", () => {
connection.open();
});

it("connectionError", (done: Function) => {
it("disconnected", (done: Function) => {
mockService.on(
rhea.ConnectionEvents.connectionOpen,
(context: rhea.EventContext) => {
Expand All @@ -122,5 +122,42 @@ describe("Connection", () => {

connection.open();
});

it("connectionError on connection.close() is bubbled up", (done: Function) => {
const errorCondition = "amqp:connection:forced";
const errorDescription = "testing error on close";
mockService.on(
rhea.ConnectionEvents.connectionClose,
(context: rhea.EventContext) => {
context.connection.close({
condition: errorCondition,
description: errorDescription,
});
}
);

const connection = new Connection({
port: mockServiceListener.address().port,
reconnect: false,
});

connection.on(ConnectionEvents.connectionOpen, async (event) => {
assert.exists(event, "Expected an AMQP event.");
try {
await connection.close();
throw new Error("boo")
} catch (error) {
assert.exists(error, "Expected an AMQP error.");
assert.strictEqual(error.condition, errorCondition);
assert.strictEqual(error.description, errorDescription);
}
done();
});

connection.open();



});
});
});

0 comments on commit 7237cf8

Please sign in to comment.