Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions handwritten/pubsub/src/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,8 @@ export class Subscriber extends EventEmitter {
const response = await this.modAckWithResponse(message, 0);
message.subSpans.nackEnd();
message.endParentSpan();
this._inventory.remove(message);

return response;
}

Expand Down
24 changes: 22 additions & 2 deletions handwritten/pubsub/test/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ describe('Subscriber', () => {
});

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

await subscriber.nack(message);
Expand All @@ -929,6 +929,17 @@ describe('Subscriber', () => {
assert.strictEqual(deadline, 0);
});

it('should modAck the message with a 0 deadline (nackWithResponse)', async () => {
const stub = sandbox.stub(subscriber, 'modAckWithResponse');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a super nit of me, but Google's unit test best practices (see go/unit-testing-practices?polyglot=typescript#structure) recommend that unit tests be structured into clear arrange, act, and assert steps with whitespace.

I think that would make your test look like this:

      const stub = sandbox.stub(subscriber, 'modAckWithResponse');
      
      await subscriber.nackWithResponse(message);

      const [msg, deadline] = stub.lastCall.args;
      assert.strictEqual(msg, message);
      assert.strictEqual(deadline, 0);

await subscriber.nackWithResponse(message);

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

assert.strictEqual(msg, message);
assert.strictEqual(deadline, 0);
});

it('should log on ack completion', async () => {
fakeLog = new FakeLog(s.logs.ackNack);

Expand All @@ -942,14 +953,23 @@ describe('Subscriber', () => {
assert.strictEqual(fakeLog.args![1], message.id);
});

it('should remove the message from the inventory', async () => {
it('should remove the message from the inventory (nack)', async () => {
const inventory: FakeLeaseManager = stubs.get('inventory');
const stub = sandbox.stub(inventory, 'remove').withArgs(message);

await subscriber.nack(message);

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

it('should remove the message from the inventory (nackWithResponse)', 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('open', () => {
Expand Down
Loading