Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add factory destroy method #825

Merged
merged 8 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
10.29.0 (September XX, 2024)
- Added `factory.destroy()` method, which invokes the `destroy` method on all SDK clients created by the factory.
- Updated @splitsoftware/splitio-commons package to version 1.18.0 that includes minor updates:
- Added support for targeting rules based on large segments for browsers.
- Updated some transitive dependencies for vulnerability fixes.
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio",
"version": "10.28.1-rc.1",
"version": "10.28.1-rc.2",
"description": "Split SDK",
"files": [
"README.md",
Expand Down Expand Up @@ -40,7 +40,7 @@
"node": ">=6"
},
"dependencies": {
"@splitsoftware/splitio-commons": "1.17.1-rc.0",
"@splitsoftware/splitio-commons": "1.17.1-rc.1",
"@types/google.analytics": "0.0.40",
"@types/ioredis": "^4.28.0",
"bloom-filters": "^3.0.0",
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/browserSuites/push-synchronization.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const config = {
},
urls: baseUrls,
streamingEnabled: true,
debug: true
};
const settings = settingsFactory(config);

Expand Down
82 changes: 21 additions & 61 deletions src/__tests__/browserSuites/readiness.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,7 @@ export default function (fetchMock, assert) {
t.equal(getMembershipsHits(), 4 * CLIENTS_COUNT - 1, 'It should have not tried to synchronize segments again after the last update that left us in a no segment state.');
t.equal(readyCount, CLIENTS_COUNT, 'all clients must be ready');

Promise.all([
client2.destroy(),
client3.destroy(),
client.destroy()
]).then(() => { t.end(); });

splitio.destroy().then(() => { t.end(); });
}, 10000);
}, 0);
});
Expand Down Expand Up @@ -293,12 +288,7 @@ export default function (fetchMock, assert) {
t.equal(getMembershipsHits(), 4 * CLIENTS_COUNT - 1, 'It should have not tried to synchronize segments again after the last update that left us in a no segment state.');
t.equal(readyCount, CLIENTS_COUNT, 'all clients must be ready');

Promise.all([
client2.destroy(),
client3.destroy(),
client.destroy()
]).then(() => { t.end(); });

splitio.destroy().then(() => { t.end(); });
}, 10000);
}, 0);
});
Expand Down Expand Up @@ -373,12 +363,7 @@ export default function (fetchMock, assert) {
t.equal(getMembershipsHits(), 6 * CLIENTS_COUNT - 1, 'It should keep the producer synchronizing periodically..');
t.equal(readyCount, CLIENTS_COUNT, 'all clients must be ready');

Promise.all([
client2.destroy(),
client3.destroy(),
client.destroy()
]).then(() => { t.end(); });

splitio.destroy().then(() => { t.end(); });
}, 3000);
}, 0);
});
Expand Down Expand Up @@ -417,8 +402,8 @@ export default function (fetchMock, assert) {
});
const CLIENTS_COUNT = 3; // Just so it's easier to read the assertions.
const client = splitio.client();
const client2 = splitio.client('[email protected]');
const client3 = splitio.client('[email protected]');
splitio.client('[email protected]');
splitio.client('[email protected]');

client.once(client.Event.SDK_READY, () => {
t.ok(Date.now() - start >= membershipsEndpointDelay, 'It should not be ready without waiting for memberships, as there are segments in the first splits payload.');
Expand All @@ -442,12 +427,7 @@ export default function (fetchMock, assert) {
setTimeout(() => {
t.equal(getMembershipsHits(), 6 * CLIENTS_COUNT, 'It should keep the producer synchronizing periodically..');

Promise.all([
client2.destroy(),
client3.destroy(),
client.destroy()
]).then(() => { t.end(); });

splitio.destroy().then(() => { t.end(); });
}, 3000);
}, 0);
});
Expand Down Expand Up @@ -486,19 +466,15 @@ export default function (fetchMock, assert) {
});
const CLIENTS_COUNT = 3; // Just so it's easier to read the assertions.
const client = splitio.client();
const client2 = splitio.client('[email protected]');
const client3 = splitio.client('[email protected]');
splitio.client('[email protected]');
splitio.client('[email protected]');

client.once(client.Event.SDK_READY, () => {
t.ok(Date.now() - start >= membershipsEndpointDelay, 'It should not be ready without waiting for memberships, when we start from cache it might be stale.');

setTimeout(() => {
t.equal(getMembershipsHits(), 3 * CLIENTS_COUNT, 'memberships should had been hit once per client on the first attempt and keep syncing afterwards.');
Promise.all([
client2.destroy(),
client3.destroy(),
client.destroy()
]).then(() => { t.end(); });
splitio.destroy().then(() => { t.end(); });
}, 2500);
});
client.once(client.Event.SDK_READY_TIMED_OUT, () => {
Expand Down Expand Up @@ -533,19 +509,15 @@ export default function (fetchMock, assert) {
});
const CLIENTS_COUNT = 3; // Just so it's easier to read the assertions.
const client = splitio.client();
const client2 = splitio.client('[email protected]');
const client3 = splitio.client('[email protected]');
splitio.client('[email protected]');
splitio.client('[email protected]');

client.once(client.Event.SDK_READY, () => {
t.ok(Date.now() - start < 50, 'It should be ready quickly, since it had no segments and update has no segments either.');

setTimeout(() => {
t.equal(getMembershipsHits(), 1 * CLIENTS_COUNT, 'memberships should had been hit once per client on the first attempt but stopped syncing afterwards');
Promise.all([
client2.destroy(),
client3.destroy(),
client.destroy()
]).then(() => { t.end(); });
splitio.destroy().then(() => { t.end(); });
}, 4500);
});
client.once(client.Event.SDK_READY_TIMED_OUT, () => {
Expand Down Expand Up @@ -584,19 +556,15 @@ export default function (fetchMock, assert) {
});
const CLIENTS_COUNT = 3; // Just so it's easier to read the assertions.
const client = splitio.client();
const client2 = splitio.client('[email protected]');
const client3 = splitio.client('[email protected]');
splitio.client('[email protected]');
splitio.client('[email protected]');

client.once(client.Event.SDK_READY, () => {
const delay = Date.now() - start;
t.ok(delay >= membershipsEndpointDelay, 'It should not be ready without waiting for memberships, when we start from cache it might be stale.');
setTimeout(() => {
t.equal(getMembershipsHits(), 3 * CLIENTS_COUNT, 'memberships should had been hit once per client on the first attempt but stopped syncing afterwards');
Promise.all([
client2.destroy(),
client3.destroy(),
client.destroy()
]).then(() => { t.end(); });
splitio.destroy().then(() => { t.end(); });
}, 3000);
});
client.once(client.Event.SDK_READY_TIMED_OUT, () => {
Expand Down Expand Up @@ -631,19 +599,15 @@ export default function (fetchMock, assert) {
});
const CLIENTS_COUNT = 3; // Just so it's easier to read the assertions.
const client = splitio.client();
const client2 = splitio.client('[email protected]');
const client3 = splitio.client('[email protected]');
splitio.client('[email protected]');
splitio.client('[email protected]');

client.once(client.Event.SDK_READY, () => {
t.ok(Date.now() - start >= membershipsEndpointDelay, 'It should not be ready without waiting for memberships, when we start from cache it might be stale and we had segments even though the update has nothing.');

setTimeout(() => {
t.equal(getMembershipsHits(), 3 * CLIENTS_COUNT, 'memberships should had been hit once per client on the first attempt and kept syncing afterwards');
Promise.all([
client2.destroy(),
client3.destroy(),
client.destroy()
]).then(() => { t.end(); });
splitio.destroy().then(() => { t.end(); });
}, 3000);
});
client.once(client.Event.SDK_READY_TIMED_OUT, () => {
Expand Down Expand Up @@ -681,19 +645,15 @@ export default function (fetchMock, assert) {
});
const CLIENTS_COUNT = 3; // Just so it's easier to read the assertions.
const client = splitio.client();
const client2 = splitio.client('[email protected]');
const client3 = splitio.client('[email protected]');
splitio.client('[email protected]');
splitio.client('[email protected]');

client.once(client.Event.SDK_READY, () => {
t.ok(Date.now() - start < 50, 'It should be ready without waiting for memberships, since when it downloads changes it will have no more use for them.');

setTimeout(() => {
t.equal(getMembershipsHits(), 1 * CLIENTS_COUNT, 'memberships should had been hit once per client on the first attempt and stopped syncing afterwards');
Promise.all([
client2.destroy(),
client3.destroy(),
client.destroy()
]).then(() => { t.end(); });
splitio.destroy().then(() => { t.end(); });
}, 3000);
});
client.once(client.Event.SDK_READY_TIMED_OUT, () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/nodeSuites/readiness.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function (fetchMock, assert) {
try {
await client.ready();
} catch (e) {
await client.destroy();
await splitio.destroy();
t.end();
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/settings/defaults/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const packageVersion = '10.28.1-rc.1';
export const packageVersion = '10.28.1-rc.2';
22 changes: 12 additions & 10 deletions ts-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,11 @@ const b: number = client.listenerCount(splitEvent);
let nodeEventEmitter: NodeJS.EventEmitter = client;

// Ready, destroy and flush
const readyPromise: Promise<void> = client.ready();
const destroyPromise: Promise<void> = client.destroy();
// @ts-ignore
const flushPromise: Promise<void> = client.flush();
let promise: Promise<void> = client.ready();
promise = client.destroy();
promise = SDK.destroy();
// @TODO not public yet
// promise = client.flush();

// We can call getTreatment with or without a key.
treatment = client.getTreatment(splitKey, 'mySplit');
Expand Down Expand Up @@ -332,10 +333,11 @@ const b1: number = asyncClient.listenerCount(splitEvent);
nodeEventEmitter = asyncClient;

// Ready, destroy and flush (same as for sync client, just for interface checking)
const readyPromise1: Promise<void> = asyncClient.ready();
asyncClient.destroy();
// @ts-ignore
asyncClient.flush();
promise = asyncClient.ready();
promise = asyncClient.destroy();
promise = AsyncSDK.destroy();
// @TODO not public yet
// promise = asyncClient.flush();

// We can call getTreatment but always with a key.
asyncTreatment = asyncClient.getTreatment(splitKey, 'mySplit');
Expand Down Expand Up @@ -391,7 +393,7 @@ splitView = manager.split('mySplit');
splitViews = manager.splits();

// Manager implements ready promise.
const managerReadyPromise: Promise<void> = manager.ready();
promise = manager.ready();

// Manager implements methods from NodeJS.Events. Testing a few.
manager = manager.on(splitEvent, () => { });
Expand All @@ -415,7 +417,7 @@ splitViewAsync = asyncManager.split('mySplit');
splitViewsAsync = asyncManager.splits();

// asyncManager implements ready promise.
const asyncManagerReadyPromise: Promise<void> = asyncManager.ready();
promise = asyncManager.ready();

// asyncManager implements methods from NodeJS.Events. Testing a few.
asyncManager = asyncManager.on(splitEvent, () => { });
Expand Down
6 changes: 6 additions & 0 deletions types/splitio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ interface IBasicSDK {
* @property Logger
*/
Logger: ILoggerAPI
/**
* Destroys all the clients created by this factory.
* @function destroy
* @returns {Promise<void>}
*/
destroy(): Promise<void>
}
/****** Exposed namespace ******/
/**
Expand Down
Loading