Skip to content

Commit 195a836

Browse files
committed
small cleanups
1 parent eaec80e commit 195a836

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

packages/polling-controller/src/PollingController.test.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('PollingController', () => {
8585
});
8686

8787
describe('setIntervalLength', () => {
88-
it('should set getNetworkClientById if previously set to undefined when setting interval length', async () => {
88+
it('should set getNetworkClientById (if previously set by setPollWithBlockTracker) to undefined when setting interval length', async () => {
8989
controller.setPollWithBlockTracker(() => {
9090
throw new Error('should not be called');
9191
});
@@ -136,6 +136,7 @@ describe('PollingController', () => {
136136
expect(controller._executePoll).toHaveBeenCalledTimes(2);
137137
});
138138
it('should start and stop polling sessions for different networkClientIds with the same options', async () => {
139+
controller.setIntervalLength(TICK_TIME);
139140
const pollToken1 = controller.startPollingByNetworkClientId('mainnet', {
140141
address: '0x1',
141142
});
@@ -180,30 +181,30 @@ describe('PollingController', () => {
180181
controller.startPollingByNetworkClientId('mainnet');
181182
await advanceTime({ clock, duration: 0 });
182183

183-
controller.startPollingByNetworkClientId('goerli');
184+
controller.startPollingByNetworkClientId('rinkeby');
184185
await advanceTime({ clock, duration: 0 });
185186

186187
expect(controller._executePoll.mock.calls).toMatchObject([
187188
['mainnet', {}],
188-
['goerli', {}],
189+
['rinkeby', {}],
189190
]);
190191
await advanceTime({ clock, duration: TICK_TIME });
191192

192193
expect(controller._executePoll.mock.calls).toMatchObject([
193194
['mainnet', {}],
194-
['goerli', {}],
195+
['rinkeby', {}],
195196
['mainnet', {}],
196-
['goerli', {}],
197+
['rinkeby', {}],
197198
]);
198199
await advanceTime({ clock, duration: TICK_TIME });
199200

200201
expect(controller._executePoll.mock.calls).toMatchObject([
201202
['mainnet', {}],
202-
['goerli', {}],
203+
['rinkeby', {}],
203204
['mainnet', {}],
204-
['goerli', {}],
205+
['rinkeby', {}],
205206
['mainnet', {}],
206-
['goerli', {}],
207+
['rinkeby', {}],
207208
]);
208209
controller.stopAllPolling();
209210
});
@@ -327,10 +328,10 @@ describe('PollingController', () => {
327328
});
328329
});
329330

330-
it('should set the interval length to 0', () => {
331+
it('should set the interval length to undefined', () => {
331332
controller.setPollWithBlockTracker(getNetworkClientById);
332333

333-
expect(controller.getIntervalLength()).toBe(0);
334+
expect(controller.getIntervalLength()).toBeUndefined();
334335
});
335336

336337
it('should start polling for the specified networkClientId', async () => {
@@ -368,7 +369,6 @@ describe('PollingController', () => {
368369
expect(controller._executePoll).toHaveBeenCalledTimes(1);
369370
expect(controller._executePoll).toHaveBeenCalledWith('mainnet', {}, 1);
370371

371-
// Start polling for goerli, 10ms interval
372372
await advanceTime({ clock, duration: 5 });
373373

374374
expect(controller._executePoll.mock.calls).toMatchObject([
@@ -450,11 +450,9 @@ describe('PollingController', () => {
450450
['mainnet', {}, 2],
451451
['mainnet', {}, 3],
452452
]);
453-
454-
controller.stopAllPolling();
455453
});
456454

457-
it('should should stop polling when all polling tokens for a networkClientId are deleted, even if other networkClientIds are still polling', async () => {
455+
it('should should stop polling for one networkClientId when all polling tokens for that networkClientId are deleted, without stopping polling for networkClientIds with active pollingTokens', async () => {
458456
controller.setPollWithBlockTracker(getNetworkClientById);
459457

460458
const pollingToken1 =

packages/polling-controller/src/PollingController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function PollingControllerMixin<TBase extends Constructor>(Base: TBase) {
5151
Set<(networkClientId: NetworkClientId) => void>
5252
> = new Map();
5353

54-
#intervalLength = 1000;
54+
#intervalLength: number | undefined = 1000;
5555

5656
#getNetworkClientById:
5757
| ((networkClientId: NetworkClientId) => NetworkClient)
@@ -87,7 +87,7 @@ function PollingControllerMixin<TBase extends Constructor>(Base: TBase) {
8787
this.#getNetworkClientById = getNetworkClientById;
8888

8989
// using block times is mutually exclusive with polling on a static interval
90-
this.#intervalLength = 0;
90+
this.#intervalLength = undefined;
9191
}
9292

9393
/**
@@ -210,7 +210,7 @@ function PollingControllerMixin<TBase extends Constructor>(Base: TBase) {
210210
}
211211

212212
throw new Error(`
213-
Unable to retreive blockTracker for networkClientId ${networkClientId} `);
213+
Unable to retrieve blockTracker for networkClientId ${networkClientId} `);
214214
}
215215

216216
// if we're not polling on new blocks, use setTimeout

0 commit comments

Comments
 (0)