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
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.4.2 (June XX, 2022)
- Added `sync.enabled` property to SDK configuration to allow synchronize splits and segments once

1.4.1 (June 13, 2022)
- Bugfixing - Updated submitters logic, to avoid dropping impressions and events that are being tracked while POST request is pending.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio-commons",
"version": "1.4.1",
"version": "1.4.2-rc.0",
"description": "Split Javascript SDK common components",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down
8 changes: 4 additions & 4 deletions src/sync/__tests__/syncManagerOnline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ test('syncManagerOnline should start or not the submitter depending on user cons

});

test('syncManagerOnline should syncAll a single time in singleSync mode', () => {
test('syncManagerOnline should syncAll a single time when sync is disabled', () => {
const settings = { ...fullSettings };

// Enable single sync
settings.sync.singleSync = true;
// disable sync
settings.sync.enabled = false;

// @ts-ignore
// Test pushManager for main client
Expand Down Expand Up @@ -151,7 +151,7 @@ test('syncManagerOnline should syncAll a single time in singleSync mode', () =>

pushingSyncManagerShared.stop();

settings.sync.singleSync = false;
settings.sync.enabled = true;
// @ts-ignore
// pushManager instantiation control test
const testSyncManager = syncManagerOnlineFactory(() => pollingManagerMock, pushManagerFactoryMock)({ settings });
Expand Down
24 changes: 12 additions & 12 deletions src/sync/syncManagerOnline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export function syncManagerOnlineFactory(
*/
return function (params: ISdkFactoryContextSync): ISyncManagerCS {

const { settings, settings: { log, streamingEnabled, sync: { singleSync } }, telemetryTracker } = params;
const { settings, settings: { log, streamingEnabled, sync: { enabled: syncEnabled } }, telemetryTracker } = params;

/** Polling Manager */
const pollingManager = pollingManagerFactory && pollingManagerFactory(params);

/** Push Manager */
const pushManager = !singleSync && streamingEnabled && pollingManager && pushManagerFactory ?
const pushManager = syncEnabled && streamingEnabled && pollingManager && pushManagerFactory ?
pushManagerFactory(params, pollingManager) :
undefined;

Expand Down Expand Up @@ -90,13 +90,8 @@ export function syncManagerOnlineFactory(
// start syncing splits and segments
if (pollingManager) {

// If singleSync is enabled pushManager and pollingManager should not start
if (singleSync === true) {
if (startFirstTime) {
pollingManager.syncAll();
startFirstTime = false;
}
} else {
// If synchronization is disabled pushManager and pollingManager should not start
if (syncEnabled) {
if (pushManager) {
// Doesn't call `syncAll` when the syncManager is resuming
if (startFirstTime) {
Expand All @@ -107,6 +102,11 @@ export function syncManagerOnlineFactory(
} else {
pollingManager.start();
}
} else {
if (startFirstTime) {
pollingManager.syncAll();
startFirstTime = false;
}
}
}

Expand Down Expand Up @@ -147,9 +147,7 @@ export function syncManagerOnlineFactory(
return {
isRunning: mySegmentsSyncTask.isRunning,
start() {
if (singleSync === true) {
if (!readinessManager.isReady()) mySegmentsSyncTask.execute();
} else {
if (syncEnabled) {
if (pushManager) {
if (pollingManager!.isRunning()) {
// if doing polling, we must start the periodic fetch of data
Expand All @@ -163,6 +161,8 @@ export function syncManagerOnlineFactory(
} else {
if (storage.splits.usesSegments()) mySegmentsSyncTask.start();
}
} else {
if (!readinessManager.isReady()) mySegmentsSyncTask.execute();
}
},
stop() {
Expand Down
8 changes: 4 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export interface ISettings {
impressionsMode: SplitIO.ImpressionsMode,
__splitFiltersValidation: ISplitFiltersValidation,
localhostMode?: SplitIO.LocalhostFactory,
singleSync: boolean
enabled: boolean
},
readonly runtime: {
ip: string | false
Expand Down Expand Up @@ -216,10 +216,10 @@ interface ISharedSettings {
*/
impressionsMode?: SplitIO.ImpressionsMode,
/**
* single Sync enables.
* @property {boolean} singleSync
* Enables synchronization.
* @property {boolean} enabled
*/
singleSync: boolean
enabled: boolean
}
}
/**
Expand Down
15 changes: 8 additions & 7 deletions src/utils/settingsValidation/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('settingsValidation', () => {
telemetry: 'https://telemetry.split.io/api',
});
expect(settings.sync.impressionsMode).toBe(OPTIMIZED);
expect(settings.sync.singleSync).toBe(false);
expect(settings.sync.enabled).toBe(true);
});

test('override with default impressionMode if provided one is invalid', () => {
Expand Down Expand Up @@ -164,23 +164,24 @@ describe('settingsValidation', () => {
expect(settingsWithStreamingEnabled.streamingEnabled).toBe(true); // If streamingEnabled is not provided, it will be true.
});

test('singleSync should be overwritable and false by default', () => {
const settingsWithSingleSyncDisabled = settingsValidation({
test('sync.enabled should be overwritable and true by default', () => {
const settingsWithSyncEnabled = settingsValidation({
core: {
authorizationKey: 'dummy token',
}
}, minimalSettingsParams);
const settingsWithSingleSyncEnabled = settingsValidation({

const settingsWithSyncDisabled = settingsValidation({
core: {
authorizationKey: 'dummy token'
},
sync: {
singleSync: true
enabled: false
}
}, minimalSettingsParams);

expect(settingsWithSingleSyncDisabled.sync.singleSync).toBe(false); // If singleSync is not provided, it will be true.
expect(settingsWithSingleSyncEnabled.sync.singleSync).toBe(true); // When creating a setting instance, it will have the provided value for singleSync
expect(settingsWithSyncDisabled.sync.enabled).toBe(false); // If sync.enabled is not provided, it will be true.
expect(settingsWithSyncEnabled.sync.enabled).toBe(true); // When creating a setting instance, it will have the provided value for sync.enabled

});

Expand Down
2 changes: 1 addition & 1 deletion src/utils/settingsValidation/__tests__/settings.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const fullSettings: ISettings = {
queryString: null,
groupedFilters: { byName: [], byPrefix: [] }
},
singleSync: false
enabled: true
},
version: 'jest',
runtime: {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/settingsValidation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const base = {
// impressions collection mode
impressionsMode: OPTIMIZED,
localhostMode: undefined,
singleSync: false
enabled: true
},

// Logger
Expand Down Expand Up @@ -192,9 +192,9 @@ export function settingsValidation(config: unknown, validationParams: ISettingsV
scheduler.pushRetryBackoffBase = fromSecondsToMillis(scheduler.pushRetryBackoffBase);
}

// validate singleSync
if (withDefaults.sync.singleSync !== true) { // @ts-ignore, modify readonly prop
withDefaults.sync.singleSync = false;
// validate sync enabled
if (withDefaults.sync.enabled !== false) { // @ts-ignore, modify readonly prop
withDefaults.sync.enabled = true;
}

// validate the `splitFilters` settings and parse splits query
Expand Down