Skip to content

Commit 8619046

Browse files
committed
ensure delivery count is set correctly on drain
1 parent 416706b commit 8619046

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

lib/link.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ Receiver.prototype.on_flow = function (frame) {
354354
this.dispatch('receiver_flow', this._context());
355355
if (frame.performative.drain) {
356356
this.credit = frame.performative.link_credit;
357+
this.delivery_count = frame.performative.delivery_count;
357358
if (frame.performative.link_credit > 0) console.error('ERROR: received flow with drain set, but non zero credit');
358359
else this.dispatch('receiver_drained', this._context());
359360
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rhea",
3-
"version": "0.3.10",
3+
"version": "0.3.11",
44
"description": "reactive AMQP 1.0 library",
55
"homepage": "http://github.com/amqp/rhea",
66
"license": "Apache-2.0",

test/links.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,4 +791,54 @@ describe('miscellaneous', function() {
791791
done();
792792
});
793793
});
794+
795+
it('handles drain correctly', function(done: Function) {
796+
var queue = [] as any;
797+
var sender: any;
798+
server.on('sender_open', function (context: rhea.EventContext) {
799+
sender = context.sender!;
800+
});
801+
server.on('sender_draining', function (context: rhea.EventContext) {
802+
context.sender!.set_drained(queue.length === 0);
803+
});
804+
server.on('receiver_open', function (context: rhea.EventContext) {
805+
context.receiver!.add_credit(100);
806+
});
807+
server.on('message', function (context: rhea.EventContext) {
808+
queue.push(context.message!.body);
809+
while (sender.sendable && queue.length) {
810+
sender.send({body:queue.shift()});
811+
}
812+
});
813+
server.on('sendable', function (context: rhea.EventContext) {
814+
while (context.sender!.sendable && queue.length) {
815+
context.sender!.send({body:queue.shift()});
816+
}
817+
});
818+
var conn = client.connect(listener.address() as any);
819+
var received: string;
820+
var r = conn.open_receiver({credit_window:0}) as any;
821+
var s = conn.open_sender() as any;
822+
r.on('message', function (context: rhea.EventContext) {
823+
received = context.message!.body;
824+
r.close();
825+
});
826+
r.once('receiver_drained', function () {
827+
s.send({body:'post-drain'});
828+
});
829+
r.drain = true;
830+
r.flow(1);
831+
s.on('accepted', function () {
832+
r.drain = true;
833+
r.flow(1);
834+
});
835+
client.on('receiver_close', function (context: rhea.EventContext) {
836+
context.connection.close();
837+
});
838+
client.on('connection_close', function (context: rhea.EventContext) {
839+
assert.deepEqual(received, 'post-drain');
840+
done();
841+
});
842+
});
843+
794844
});

0 commit comments

Comments
 (0)