From 7237cf86a214431dc11639a920184196e911f510 Mon Sep 17 00:00:00 2001 From: Ramya Rao Date: Tue, 28 Jul 2020 15:05:02 -0700 Subject: [PATCH] Test for error on connection.close() bubbling up (#62) --- test/connection.spec.ts | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/test/connection.spec.ts b/test/connection.spec.ts index 6dc0e07..d9be7da 100644 --- a/test/connection.spec.ts +++ b/test/connection.spec.ts @@ -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( @@ -98,7 +98,7 @@ describe("Connection", () => { connection.open(); }); - it("connectionError", (done: Function) => { + it("disconnected", (done: Function) => { mockService.on( rhea.ConnectionEvents.connectionOpen, (context: rhea.EventContext) => { @@ -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(); + + + + }); }); });