Skip to content
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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eppo/node-server-sdk",
"version": "3.11.0",
"version": "3.12.0",
"description": "Eppo node server SDK",
"main": "dist/index.js",
"files": [
Expand Down
6 changes: 6 additions & 0 deletions src/i-client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export interface IClientConfig {
/** Poll for new configurations even if the initial configuration request failed. (default: false) */
pollAfterFailedInitialization?: boolean;

/**
* Poll for new configurations (every `pollingIntervalMs`) after successfully requesting the initial configuration. (default: true)
* For server-side applications, this defaults to true to ensure configurations stay up-to-date for the life of the process.
*/
pollAfterSuccessfulInitialization?: boolean;

/** Amount of time in milliseconds to wait between API calls to refresh configuration data. Default of 30_000 (30s). */
pollingIntervalMs?: number;

Expand Down
27 changes: 27 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,4 +708,31 @@
});
});
});

describe('pollAfterSuccessfulInitialization', () => {
it('should default to true when not specified', async () => {
const client = await init({
apiKey,
baseUrl: `http://127.0.0.1:${TEST_SERVER_PORT}`,
assignmentLogger: mockLogger,
});

Check warning on line 719 in src/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (23)

Delete `Β·Β·Β·Β·Β·Β·`

Check warning on line 719 in src/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (18)

Delete `Β·Β·Β·Β·Β·Β·`

Check warning on line 719 in src/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (22)

Delete `Β·Β·Β·Β·Β·Β·`

Check warning on line 719 in src/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (20)

Delete `Β·Β·Β·Β·Β·Β·`
// Access the internal configurationRequestParameters to verify the default
const configurationRequestParameters = client['configurationRequestParameters'];
expect(configurationRequestParameters.pollAfterSuccessfulInitialization).toBe(true);
});

it('should use the provided value when specified', async () => {
const client = await init({
apiKey,
baseUrl: `http://127.0.0.1:${TEST_SERVER_PORT}`,
assignmentLogger: mockLogger,
pollAfterSuccessfulInitialization: false,
});

Check warning on line 732 in src/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (23)

Delete `Β·Β·Β·Β·Β·Β·`

Check warning on line 732 in src/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (18)

Delete `Β·Β·Β·Β·Β·Β·`

Check warning on line 732 in src/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (22)

Delete `Β·Β·Β·Β·Β·Β·`

Check warning on line 732 in src/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (20)

Delete `Β·Β·Β·Β·Β·Β·`
// Access the internal configurationRequestParameters to verify the custom value
const configurationRequestParameters = client['configurationRequestParameters'];
expect(configurationRequestParameters.pollAfterSuccessfulInitialization).toBe(false);
Comment on lines +734 to +735
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we set a super short poll interval and verify it didn't actually try to poll, but I think peeking at the internals is fine enough.

});
});
});
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export async function init(config: IClientConfig): Promise<EppoClient> {
requestTimeoutMs,
numInitialRequestRetries,
numPollRequestRetries,
// For server-side, we always want to keep polling for the life of the process
pollAfterSuccessfulInitialization: true,
// For server-side, we default to keep polling for the life of the process
pollAfterSuccessfulInitialization: config.pollAfterSuccessfulInitialization ?? true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘

pollAfterFailedInitialization,
pollingIntervalMs,
throwOnFailedInitialization,
Expand Down