diff --git a/src/subscriber.ts b/src/subscriber.ts index c12996862..9d2f4ced7 100644 --- a/src/subscriber.ts +++ b/src/subscriber.ts @@ -1096,6 +1096,8 @@ export class Subscriber extends EventEmitter { const latency = (Date.now() - startTime) / 1000; this._latencies.add(latency); + this._inventory.remove(message); + // No exception means Success. return AckResponses.Success; } diff --git a/test/subscriber.ts b/test/subscriber.ts index 4e6917b15..e79d6d63e 100644 --- a/test/subscriber.ts +++ b/test/subscriber.ts @@ -918,10 +918,32 @@ describe('Subscriber', () => { }); describe('nack', () => { + it('should remove the message from the inventory', async () => { + const inventory: FakeLeaseManager = stubs.get('inventory'); + const stub = sandbox.stub(inventory, 'remove').withArgs(message); + + await subscriber.nack(message); + + assert.strictEqual(stub.callCount, 1); + }); + }); + + describe('nackWithResponse', () => { + it('should remove the message from the inventory', async () => { + const inventory: FakeLeaseManager = stubs.get('inventory'); + const stub = sandbox.stub(inventory, 'remove').withArgs(message); + + await subscriber.nackWithResponse(message); + + assert.strictEqual(stub.callCount, 1); + }); + }); + + describe('ackWithResponse', () => { it('should modAck the message with a 0 deadline', async () => { const stub = sandbox.stub(subscriber, 'modAck'); - await subscriber.nack(message); + await subscriber.ackWithResponse(message); const [msg, deadline] = stub.lastCall.args; @@ -946,7 +968,7 @@ describe('Subscriber', () => { const inventory: FakeLeaseManager = stubs.get('inventory'); const stub = sandbox.stub(inventory, 'remove').withArgs(message); - await subscriber.nack(message); + await subscriber.ackWithResponse(message); assert.strictEqual(stub.callCount, 1); });