Skip to content

Commit

Permalink
add intervallength test
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Sep 25, 2023
1 parent fac9924 commit 911ff20
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions packages/polling-controller/src/PollingController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,35 @@ describe('PollingController', () => {
controller.stop(pollingToken);
expect(pollingComplete).toHaveBeenCalledTimes(1);
});
it('should poll at the interval length passed via the constructor', async () => {
jest.useFakeTimers();

class MyGasFeeController extends PollingController<any, any, any> {
executePoll = createExecutePollMock();
}
const mockMessenger = new ControllerMessenger<any, any>();

const controller = new MyGasFeeController({
messenger: mockMessenger,
metadata: {},
name: 'PollingController',
state: { foo: 'bar' },
pollingIntervalLength: TICK_TIME * 3,
});
controller.start('mainnet');
jest.advanceTimersByTime(TICK_TIME);
await Promise.resolve();
expect(controller.executePoll).not.toHaveBeenCalled();
jest.advanceTimersByTime(TICK_TIME);
await Promise.resolve();
expect(controller.executePoll).not.toHaveBeenCalled();
jest.advanceTimersByTime(TICK_TIME);
await Promise.resolve();
expect(controller.executePoll).toHaveBeenCalledTimes(1);
jest.advanceTimersByTime(TICK_TIME * 3);
await Promise.resolve();
expect(controller.executePoll).toHaveBeenCalledTimes(2);
});
});
describe('multiple networkClientIds', () => {
it('should poll for each networkClientId', async () => {
Expand Down Expand Up @@ -229,5 +258,51 @@ describe('PollingController', () => {
]);
controller.stopAll();
});

it('should poll multiple networkClientIds at the interval length passed via the constructor', async () => {
jest.useFakeTimers();

class MyGasFeeController extends PollingController<any, any, any> {
executePoll = createExecutePollMock();
}
const mockMessenger = new ControllerMessenger<any, any>();

const controller = new MyGasFeeController({
messenger: mockMessenger,
metadata: {},
name: 'PollingController',
state: { foo: 'bar' },
pollingIntervalLength: TICK_TIME * 2,
});
controller.start('mainnet');
jest.advanceTimersByTime(TICK_TIME);
await Promise.resolve();
controller.start('sepolia');
expect(controller.executePoll.mock.calls).toMatchObject([]);
jest.advanceTimersByTime(TICK_TIME);
await Promise.resolve();
expect(controller.executePoll.mock.calls).toMatchObject([['mainnet']]);
jest.advanceTimersByTime(TICK_TIME);
await Promise.resolve();
expect(controller.executePoll.mock.calls).toMatchObject([
['mainnet'],
['sepolia'],
]);
jest.advanceTimersByTime(TICK_TIME);
await Promise.resolve();
expect(controller.executePoll.mock.calls).toMatchObject([
['mainnet'],
['sepolia'],
['mainnet'],
]);
jest.advanceTimersByTime(TICK_TIME);
await Promise.resolve();
expect(controller.executePoll.mock.calls).toMatchObject([
['mainnet'],
['sepolia'],
['mainnet'],
['sepolia'],
]);
});
});
});

0 comments on commit 911ff20

Please sign in to comment.