Skip to content

Commit 846dabb

Browse files
committed
chore: add retry count and wait time to constants
1 parent 301ba12 commit 846dabb

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/channel_manager.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import {
2222
waitSeconds,
2323
} from './utils';
2424
import { generateUUIDv4 } from './utils';
25+
import {
26+
DEFAULT_QUERY_CHANNELS_RETRY_COUNT,
27+
DEFAULT_QUERY_CHANNELS_SECONDS_BETWEEN_RETRIES,
28+
} from './constants';
2529

2630
export type ChannelManagerPagination = {
2731
filters: ChannelFilters;
@@ -291,8 +295,7 @@ export class ChannelManager {
291295
{ method: 'upsertCidsForQuery' },
292296
);
293297
} catch (err) {
294-
// TODO: Extract this as a constant
295-
if (retryCount >= 2) {
298+
if (retryCount >= DEFAULT_QUERY_CHANNELS_RETRY_COUNT) {
296299
console.warn(err);
297300

298301
const wrappedError = new Error(
@@ -303,8 +306,7 @@ export class ChannelManager {
303306
return;
304307
}
305308

306-
// TODO: Maybe make this configurable ?
307-
await waitSeconds(2);
309+
await waitSeconds(DEFAULT_QUERY_CHANNELS_SECONDS_BETWEEN_RETRIES);
308310

309311
return this.queryChannelsRequest(payload, retryCount + 1);
310312
}

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ export const RESERVED_UPDATED_MESSAGE_FIELDS = {
2626
__html: true,
2727
user: true,
2828
} as const;
29-
3029
export const LOCAL_MESSAGE_FIELDS = { error: true } as const;
30+
export const DEFAULT_QUERY_CHANNELS_RETRY_COUNT = 3;
31+
export const DEFAULT_QUERY_CHANNELS_SECONDS_BETWEEN_RETRIES = 1;

test/unit/channel_manager.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import * as utils from '../../src/utils';
1717

1818
import { describe, beforeEach, afterEach, expect, it, vi, MockInstance } from 'vitest';
1919
import { MockOfflineDB } from './offline-support/MockOfflineDB';
20+
import { DEFAULT_QUERY_CHANNELS_RETRY_COUNT } from '../../src/constants';
2021

2122
describe('ChannelManager', () => {
2223
let client: StreamChat;
@@ -740,8 +741,12 @@ describe('ChannelManager', () => {
740741

741742
const { channels, initialized } = channelManager.state.getLatestValue();
742743

743-
expect(clientQueryChannelsStub.callCount).to.equal(3); // initial + 2 retries
744-
expect(waitSecondsSpy).toHaveBeenCalledTimes(2);
744+
expect(clientQueryChannelsStub.callCount).to.equal(
745+
DEFAULT_QUERY_CHANNELS_RETRY_COUNT + 1,
746+
); // // initial + however many retried are configured
747+
expect(waitSecondsSpy).toHaveBeenCalledTimes(
748+
DEFAULT_QUERY_CHANNELS_RETRY_COUNT,
749+
);
745750
expect(stateChangeSpy.callCount).to.equal(1);
746751
expect(stateChangeSpy.args[0][0]).to.deep.equal({
747752
error: new Error(

0 commit comments

Comments
 (0)