Skip to content

Commit

Permalink
test: add unit tests on session buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioArnt authored and grs committed Mar 10, 2023
1 parent ee8c088 commit f902e4f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
76 changes: 76 additions & 0 deletions test/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion typings/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f902e4f

Please sign in to comment.