From f902e4febe7b03422c2b249c2663da2084c8b23e Mon Sep 17 00:00:00 2001 From: Mario Arnautou Date: Fri, 10 Mar 2023 12:07:38 +0100 Subject: [PATCH] test: add unit tests on session buffer size --- test/sessions.ts | 76 +++++++++++++++++++++++++++++++++++++++++ typings/connection.d.ts | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/test/sessions.ts b/test/sessions.ts index 1014717..c2125b8 100644 --- a/test/sessions.ts +++ b/test/sessions.ts @@ -65,6 +65,82 @@ describe('session error handling', function () { context.connection.close(); }); }); + it('session buffer size [default]', function(done) { + container.on('session_open', function (context: rhea.EventContext) { + assert.equal((s as any).incoming.deliveries.capacity, 2048); + assert.equal((s as any).outgoing.deliveries.capacity, 2048); + context.session!.close({ condition: 'amqp:internal-error', description: 'testing error on close' }); + }); + container.on('session_close', function (context) { + assert.equal(context.session.is_closed(), true); + }); + var c: rhea.Connection = container.connect(listener.address()); + c.on('connection_close', function () { + done(); + }); + var s = c.create_session(); + s.begin(); + s.on('session_close', function (context: rhea.EventContext) { + context.connection.close(); + }); + }); + it('session buffer size [number]', function(done) { + container.on('session_open', function (context: rhea.EventContext) { + assert.equal((s as any).incoming.deliveries.capacity, 4096); + assert.equal((s as any).outgoing.deliveries.capacity, 4096); + context.session!.close({ condition: 'amqp:internal-error', description: 'testing error on close' }); + }); + container.on('session_close', function (context) { + assert.equal(context.session.is_closed(), true); + }); + var c: rhea.Connection = container.connect(listener.address()); + c.on('connection_close', function () { + done(); + }); + var s = c.create_session(4096); + s.begin(); + s.on('session_close', function (context: rhea.EventContext) { + context.connection.close(); + }); + }); + it('session buffer size [object]', function(done) { + container.on('session_open', function (context: rhea.EventContext) { + assert.equal((s as any).incoming.deliveries.capacity, 2048); + assert.equal((s as any).outgoing.deliveries.capacity, 4096); + context.session!.close({ condition: 'amqp:internal-error', description: 'testing error on close' }); + }); + container.on('session_close', function (context) { + assert.equal(context.session.is_closed(), true); + }); + var c: rhea.Connection = container.connect(listener.address()); + c.on('connection_close', function () { + done(); + }); + var s = c.create_session({ incoming: 2048, outgoing: 4096 }); + s.begin(); + s.on('session_close', function (context: rhea.EventContext) { + context.connection.close(); + }); + }); + it('session buffer size [invalid]', function(done) { + container.on('session_open', function (context: rhea.EventContext) { + assert.equal((s as any).incoming.deliveries.capacity, 2048); + assert.equal((s as any).outgoing.deliveries.capacity, 2048); + context.session!.close({ condition: 'amqp:internal-error', description: 'testing error on close' }); + }); + container.on('session_close', function (context) { + assert.equal(context.session.is_closed(), true); + }); + var c: rhea.Connection = container.connect(listener.address()); + c.on('connection_close', function () { + done(); + }); + var s = c.create_session('invalid' as unknown as number); + s.begin(); + s.on('session_close', function (context: rhea.EventContext) { + context.connection.close(); + }); + }); it('error handled', function (done: Function) { var error_handler_called: boolean; container.on('session_open', function (context: rhea.EventContext) { diff --git a/typings/connection.d.ts b/typings/connection.d.ts index 22a16e3..d47db91 100644 --- a/typings/connection.d.ts +++ b/typings/connection.d.ts @@ -696,7 +696,7 @@ export declare interface Connection extends EventEmitter { * @returns {boolean} `true` - closed, `false` otherwise. */ is_closed(): boolean; - create_session(): Session; + create_session(session_buffer_size?: number | { incoming?: number, outgoing?: number }): Session; find_sender(filter: Function): Sender | undefined; find_receiver(filter: Function): Receiver | undefined; find_link(filter: Function): link | undefined;