Skip to content

Commit 9a2ca06

Browse files
committed
fix: remove message from inventory when nack with response
1 parent 7a85349 commit 9a2ca06

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/subscriber.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,8 @@ export class Subscriber extends EventEmitter {
887887
const latency = (Date.now() - startTime) / 1000;
888888
this._latencies.add(latency);
889889

890+
this._inventory.remove(message);
891+
890892
// No exception means Success.
891893
return AckResponses.Success;
892894
}

test/subscriber.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,32 @@ describe('Subscriber', () => {
698698
});
699699

700700
describe('nack', () => {
701+
it('should remove the message from the inventory', async () => {
702+
const inventory: FakeLeaseManager = stubs.get('inventory');
703+
const stub = sandbox.stub(inventory, 'remove').withArgs(message);
704+
705+
await subscriber.nack(message);
706+
707+
assert.strictEqual(stub.callCount, 1);
708+
});
709+
});
710+
711+
describe('nackWithResponse', () => {
712+
it('should remove the message from the inventory', async () => {
713+
const inventory: FakeLeaseManager = stubs.get('inventory');
714+
const stub = sandbox.stub(inventory, 'remove').withArgs(message);
715+
716+
await subscriber.nackWithResponse(message);
717+
718+
assert.strictEqual(stub.callCount, 1);
719+
});
720+
});
721+
722+
describe('ackWithResponse', () => {
701723
it('should modAck the message with a 0 deadline', async () => {
702724
const stub = sandbox.stub(subscriber, 'modAck');
703725

704-
await subscriber.nack(message);
726+
await subscriber.ackWithResponse(message);
705727

706728
const [msg, deadline] = stub.lastCall.args;
707729

@@ -713,7 +735,7 @@ describe('Subscriber', () => {
713735
const inventory: FakeLeaseManager = stubs.get('inventory');
714736
const stub = sandbox.stub(inventory, 'remove').withArgs(message);
715737

716-
await subscriber.nack(message);
738+
await subscriber.ackWithResponse(message);
717739

718740
assert.strictEqual(stub.callCount, 1);
719741
});

0 commit comments

Comments
 (0)