Skip to content

Commit 841f0ca

Browse files
authored
fix(pubsub): remove messages from leasing on nackWithResponse (googleapis#7817)
* fix(pubsub): remove messages from leasing on nackWithResponse * chore: remove extra whitespace in test
1 parent 09cd24f commit 841f0ca

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

handwritten/pubsub/src/subscriber.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,8 @@ export class Subscriber extends EventEmitter {
11631163
const response = await this.modAckWithResponse(message, 0);
11641164
message.subSpans.nackEnd();
11651165
message.endParentSpan();
1166+
this._inventory.remove(message);
1167+
11661168
return response;
11671169
}
11681170

handwritten/pubsub/test/subscriber.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,13 +918,22 @@ describe('Subscriber', () => {
918918
});
919919

920920
describe('nack', () => {
921-
it('should modAck the message with a 0 deadline', async () => {
921+
it('should modAck the message with a 0 deadline (nack)', async () => {
922922
const stub = sandbox.stub(subscriber, 'modAck');
923923

924924
await subscriber.nack(message);
925925

926926
const [msg, deadline] = stub.lastCall.args;
927+
assert.strictEqual(msg, message);
928+
assert.strictEqual(deadline, 0);
929+
});
930+
931+
it('should modAck the message with a 0 deadline (nackWithResponse)', async () => {
932+
const stub = sandbox.stub(subscriber, 'modAckWithResponse');
927933

934+
await subscriber.nackWithResponse(message);
935+
936+
const [msg, deadline] = stub.lastCall.args;
928937
assert.strictEqual(msg, message);
929938
assert.strictEqual(deadline, 0);
930939
});
@@ -942,14 +951,23 @@ describe('Subscriber', () => {
942951
assert.strictEqual(fakeLog.args![1], message.id);
943952
});
944953

945-
it('should remove the message from the inventory', async () => {
954+
it('should remove the message from the inventory (nack)', async () => {
946955
const inventory: FakeLeaseManager = stubs.get('inventory');
947956
const stub = sandbox.stub(inventory, 'remove').withArgs(message);
948957

949958
await subscriber.nack(message);
950959

951960
assert.strictEqual(stub.callCount, 1);
952961
});
962+
963+
it('should remove the message from the inventory (nackWithResponse)', async () => {
964+
const inventory: FakeLeaseManager = stubs.get('inventory');
965+
const stub = sandbox.stub(inventory, 'remove').withArgs(message);
966+
967+
await subscriber.nackWithResponse(message);
968+
969+
assert.strictEqual(stub.callCount, 1);
970+
});
953971
});
954972

955973
describe('open', () => {

0 commit comments

Comments
 (0)