Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(typescript):noImplicitAny for Histogram and Message_queues test file #510

Merged
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: 1 addition & 1 deletion test/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as assert from 'assert';
import {Histogram} from '../src/histogram.js';

describe('Histogram', () => {
let histogram;
let histogram: Histogram;

const MIN_VALUE = 10000;
const MAX_VALUE = 600000;
Expand Down
61 changes: 36 additions & 25 deletions test/message-queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@

import * as assert from 'assert';
import {EventEmitter} from 'events';
import {CallOptions} from 'google-gax';
import {Metadata, ServiceError} from 'grpc';
import * as proxyquire from 'proxyquire';
import * as sinon from 'sinon';
import * as uuid from 'uuid';

import * as messageTypes from '../src/message-queues';
import {BatchError} from '../src/message-queues';
import {Message, Subscriber} from '../src/subscriber';

class FakeClient {
async acknowledge(reqOpts, callOptions): Promise<void> {}
async modifyAckDeadline(reqOpts, callOptions): Promise<void> {}
async acknowledge(
reqOpts: {subscription: string, ackIds: string[]},
callOptions: CallOptions): Promise<void> {}
async modifyAckDeadline(
reqOpts:
{subscription: string, ackIds: string[], ackDeadlineSeconds: number},
callOptions: CallOptions): Promise<void> {}
}

class FakeSubscriber extends EventEmitter {
Expand All @@ -52,14 +60,14 @@ class FakeMessage {
describe('MessageQueues', () => {
const sandbox = sinon.createSandbox();

let subscriber;
let subscriber: FakeSubscriber;

// tslint:disable-next-line variable-name no-any
let MessageQueue: any;
// tslint:disable-next-line variable-name
let MessageQueue;
let AckQueue: typeof messageTypes.AckQueue;
// tslint:disable-next-line variable-name
let AckQueue;
// tslint:disable-next-line variable-name
let ModAckQueue;
let ModAckQueue: typeof messageTypes.ModAckQueue;

before(() => {
const queues = proxyquire('../src/message-queues.js', {});
Expand All @@ -84,7 +92,7 @@ describe('MessageQueues', () => {
afterEach(() => sandbox.restore());

describe('MessageQueue', () => {
let messageQueue;
let messageQueue: typeof MessageQueue;

beforeEach(() => {
messageQueue = new MessageQueue(subscriber);
Expand Down Expand Up @@ -116,15 +124,15 @@ describe('MessageQueues', () => {

describe('add', () => {
it('should increase the number of pending requests', () => {
messageQueue.add(new FakeMessage());
messageQueue.add(new FakeMessage() as Message);
assert.strictEqual(messageQueue.numPendingRequests, 1);
});

it('should flush the queue if at capacity', () => {
const stub = sandbox.stub(messageQueue, 'flush');

messageQueue.setOptions({maxMessages: 1});
messageQueue.add(new FakeMessage());
messageQueue.add(new FakeMessage() as Message);

assert.strictEqual(stub.callCount, 1);
});
Expand All @@ -135,7 +143,7 @@ describe('MessageQueues', () => {
const delay = 1000;

messageQueue.setOptions({maxMilliseconds: delay});
messageQueue.add(new FakeMessage());
messageQueue.add(new FakeMessage() as Message);

assert.strictEqual(stub.callCount, 0);
clock.tick(delay);
Expand All @@ -150,15 +158,15 @@ describe('MessageQueues', () => {
const delay = 1000;

messageQueue.setOptions({maxMilliseconds: delay});
messageQueue.add(new FakeMessage());
messageQueue.add(new FakeMessage() as Message);
messageQueue.flush();
clock.tick(delay);

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

it('should remove the messages from the queue', () => {
messageQueue.add(new FakeMessage());
messageQueue.add(new FakeMessage() as Message);
messageQueue.flush();

assert.strictEqual(messageQueue.numPendingRequests, 0);
Expand All @@ -168,7 +176,7 @@ describe('MessageQueues', () => {
const message = new FakeMessage();
const deadline = 10;

messageQueue.add(message, deadline);
messageQueue.add(message as Message, deadline);
messageQueue.flush();

const expectedBatch = [[message.ackId, deadline]];
Expand Down Expand Up @@ -263,10 +271,10 @@ describe('MessageQueues', () => {
});

describe('AckQueue', () => {
let ackQueue;
let ackQueue: messageTypes.AckQueue;

beforeEach(() => {
ackQueue = new AckQueue(subscriber);
ackQueue = new AckQueue(subscriber as {} as Subscriber);
});

it('should send batches via Client#acknowledge', async () => {
Expand All @@ -282,7 +290,7 @@ describe('MessageQueues', () => {
ackIds: messages.map(({ackId}) => ackId),
};

messages.forEach(message => ackQueue.add(message));
messages.forEach(message => ackQueue.add(message as Message));
await ackQueue.flush();

const [reqOpts] = stub.lastCall.args;
Expand Down Expand Up @@ -326,16 +334,16 @@ describe('MessageQueues', () => {
done();
});

messages.forEach(message => ackQueue.add(message));
messages.forEach(message => ackQueue.add(message as Message));
ackQueue.flush();
});
});

describe('ModAckQueue', () => {
let modAckQueue;
let modAckQueue: messageTypes.ModAckQueue;

beforeEach(() => {
modAckQueue = new ModAckQueue(subscriber);
modAckQueue = new ModAckQueue(subscriber as {} as Subscriber);
});

it('should send batches via Client#modifyAckDeadline', async () => {
Expand All @@ -355,7 +363,8 @@ describe('MessageQueues', () => {
ackIds: messages.map(({ackId}) => ackId),
};

messages.forEach(message => modAckQueue.add(message, deadline));
messages.forEach(
message => modAckQueue.add(message as Message, deadline));
await modAckQueue.flush();

const [reqOpts] = stub.lastCall.args;
Expand Down Expand Up @@ -386,8 +395,10 @@ describe('MessageQueues', () => {
ackIds: messages2.map(({ackId}) => ackId),
};

messages1.forEach(message => modAckQueue.add(message, deadline1));
messages2.forEach(message => modAckQueue.add(message, deadline2));
messages1.forEach(
message => modAckQueue.add(message as Message, deadline1));
messages2.forEach(
message => modAckQueue.add(message as Message, deadline2));
await modAckQueue.flush();

const [reqOpts1] = stub.getCall(0).args;
Expand All @@ -403,7 +414,7 @@ describe('MessageQueues', () => {
sandbox.stub(subscriber.client, 'modifyAckDeadline').resolves();

modAckQueue.setOptions({callOptions: fakeCallOptions});
modAckQueue.add(new FakeMessage(), 10);
modAckQueue.add(new FakeMessage() as Message, 10);
await modAckQueue.flush();

const [, callOptions] = stub.lastCall.args;
Expand Down Expand Up @@ -436,7 +447,7 @@ describe('MessageQueues', () => {
done();
});

messages.forEach(message => modAckQueue.add(message));
messages.forEach(message => modAckQueue.add(message as Message));
modAckQueue.flush();
});
});
Expand Down