Skip to content

Commit

Permalink
Revert "chore: add default /init timeout of 3 seconds" (#433)
Browse files Browse the repository at this point in the history
Revert "chore: add default /init timeout of 3 seconds (#392)"

This reverts commit c0fdda6.
  • Loading branch information
kat-statsig authored Feb 6, 2025
1 parent c0fdda6 commit 19c36c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 134 deletions.
17 changes: 9 additions & 8 deletions packages/client-core/src/DataAdapterCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { _typedJsonParse } from './TypedJsonParse';

const CACHE_LIMIT = 10;
const DEFAULT_TIMEOUT_MS = 3000;

export abstract class DataAdapterCore {
protected _options: AnyStatsigOptions | null = null;

Expand Down Expand Up @@ -82,13 +82,14 @@ export abstract class DataAdapterCore {

const ops = [this._fetchAndPrepFromNetwork(cache, user, options)];

const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
ops.push(
new Promise((r) => setTimeout(r, timeoutMs)).then(() => {
Log.debug('Fetching latest value timed out');
return null;
}),
);
if (options?.timeoutMs) {
ops.push(
new Promise((r) => setTimeout(r, options.timeoutMs)).then(() => {
Log.debug('Fetching latest value timed out');
return null;
}),
);
}

return await Promise.race(ops);
}
Expand Down
123 changes: 0 additions & 123 deletions packages/combo/src/__tests__/AsyncTimeouts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('Async Timeouts', () => {
let client: StatsigOnDeviceEvalClient;

beforeAll(async () => {
storage.clear();
__STATSIG__ = {} as StatsigGlobal;
resetResolver();

Expand Down Expand Up @@ -95,69 +94,10 @@ describe('Async Timeouts', () => {
});
});

describe('StatsigOnDeviceEvalClient.initializeAsync Default Timeouts', () => {
let client: StatsigOnDeviceEvalClient;
let timeToInit: number;

beforeAll(async () => {
storage.clear();
jest.useFakeTimers({ doNotFake: ['performance'] });
__STATSIG__ = {} as StatsigGlobal;
resetResolver();

client = new StatsigOnDeviceEvalClient('client-key');

const start = Date.now();
const promise = client.initializeAsync();
jest.advanceTimersByTime(3000);
await promise;
timeToInit = Date.now() - start;
});

afterAll(() => {
jest.useRealTimers();
});

it('applies default timeout', () => {
expect(timeToInit).toBeLessThan(3500);
});

it('gets eval reason of NoValues', () => {
expect(
client.getDynamicConfig('a_dynamic_config', {}).details.reason,
).toBe('NoValues');
});

it('does not write anything to cache', () => {
expect(
storage.data['statsig.cached.specs.' + onDeviceCacheKey],
).toBeUndefined();
});

describe('then the network comes back', () => {
beforeAll(async () => {
resolver.resolve(DCS_RESPONSE());
});

it('does not update the current values, still returns NoValues', () => {
expect(
client.getDynamicConfig('a_dynamic_config', {}).details.reason,
).toBe('NoValues');
});

it('writes the values to cache for the next update', () => {
expect(
storage.data['statsig.cached.specs.' + onDeviceCacheKey],
).toEqual(anyString());
});
});
});

describe('StatsigClient.updateUserAsync Timeouts', () => {
let client: StatsigClient;

beforeAll(async () => {
storage.clear();
__STATSIG__ = {} as StatsigGlobal;
resetResolver();

Expand Down Expand Up @@ -199,67 +139,4 @@ describe('Async Timeouts', () => {
});
});
});

describe('StatsigClient.updateUserAsync Default Timeouts', () => {
let client: StatsigClient;
let timeToInit: number;

beforeAll(async () => {
storage.clear();
jest.useFakeTimers({ doNotFake: ['performance'] });
__STATSIG__ = {} as StatsigGlobal;
resetResolver();

client = new StatsigClient(
'client-key',
{},
{ customUserCacheKeyFunc: () => 'my-custom-cache' },
);

const start = Date.now();
const promise = client.updateUserAsync({ userID: 'a-user' });
jest.advanceTimersByTime(3000);
await promise;

timeToInit = Date.now() - start;
});

afterAll(() => {
jest.useRealTimers();
});

it('applies default timeout', () => {
expect(timeToInit).toBeLessThan(3500);
});

it('gets eval reason of NoValues', () => {
expect(client.getDynamicConfig('a_dynamic_config').details.reason).toBe(
'NoValues',
);
});

it('does not write anything to cache', () => {
expect(
storage.data['statsig.cached.evaluations.my-custom-cache'],
).toBeUndefined();
});

describe('then the network comes back', () => {
beforeAll(async () => {
resolver.resolve(INIT_RESPONSE());
});

it('does not update the current values, still returns NoValues', () => {
expect(client.getDynamicConfig('a_dynamic_config').details.reason).toBe(
'NoValues',
);
});

it('writes the values to cache for the next update', () => {
expect(
storage.data['statsig.cached.evaluations.my-custom-cache'],
).toEqual(anyString());
});
});
});
});
4 changes: 1 addition & 3 deletions packages/combo/src/__tests__/MemoryLeak.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,10 @@ describe('Memory Usage', () => {
{},
{ logLevel: LogLevel.None },
);
await instance.initializeAsync({ timeoutMs: 1 });
await instance.initializeAsync();
instance.checkGate('gate1');
}

await new Promise((resolve) => setTimeout(resolve, 2)); // wait for all the settimeout to resolve

await runGarbageCollection();

const finalMemory = process.memoryUsage().heapUsed;
Expand Down

0 comments on commit 19c36c1

Please sign in to comment.