Skip to content

Commit 5a37cb7

Browse files
Merge pull request #814 from splitio/SDK-8407_e2e_tests_polling
Large Segments tests: polling mode
2 parents 79fdb4a + 2838820 commit 5a37cb7

File tree

15 files changed

+122
-44
lines changed

15 files changed

+122
-44
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"node": ">=6"
4141
},
4242
"dependencies": {
43-
"@splitsoftware/splitio-commons": "1.16.1-rc.0",
43+
"@splitsoftware/splitio-commons": "1.16.1-rc.3",
4444
"@types/google.analytics": "0.0.40",
4545
"@types/ioredis": "^4.28.0",
4646
"bloom-filters": "^3.0.0",

src/__tests__/browserSuites/push-fallbacking.spec.js renamed to src/__tests__/browserSuites/push-fallback.spec.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ const userKey = 'nicolas@split.io';
3939
const secondUserKey = 'marcio@split.io';
4040

4141
const baseUrls = {
42-
sdk: 'https://sdk.push-fallbacking/api',
43-
events: 'https://events.push-fallbacking/api',
44-
auth: 'https://auth.push-fallbacking/api'
42+
sdk: 'https://sdk.push-fallback/api',
43+
events: 'https://events.push-fallback/api',
44+
auth: 'https://auth.push-fallback/api'
4545
};
4646
const config = {
4747
core: {
@@ -51,11 +51,14 @@ const config = {
5151
scheduler: {
5252
featuresRefreshRate: 0.2,
5353
segmentsRefreshRate: 0.25,
54+
largeSegmentsRefreshRate: 0.25,
5455
impressionsRefreshRate: 3000
5556
},
5657
urls: baseUrls,
5758
streamingEnabled: true,
58-
// debug: true,
59+
sync: {
60+
largeSegmentsEnabled: true
61+
}
5962
};
6063
const settings = settingsFactory(config);
6164

@@ -79,30 +82,31 @@ const MILLIS_DESTROY = MILLIS_STREAMING_DISABLED_CONTROL + settings.scheduler.fe
7982

8083
/**
8184
* Sequence of calls:
82-
* 0.0 secs: initial SyncAll (/splitChanges, /mySegments/*), auth, SSE connection
83-
* 0.1 secs: SSE connection opened -> syncAll (/splitChanges, /mySegments/nicolas)
84-
* 0.2 secs: Streaming down (OCCUPANCY event) -> fetch due to fallback to polling (/splitChanges, /mySegments/nicolas)
85+
* 0.0 secs: initial SyncAll (/splitChanges, /my(Large)Segments/nicolas), auth, SSE connection
86+
* 0.1 secs: SSE connection opened -> syncAll (/splitChanges, /my(Large)Segments/nicolas)
87+
* 0.2 secs: Streaming down (OCCUPANCY event) -> fetch due to fallback to polling (/splitChanges, /my(Large)Segments/nicolas)
8588
* 0.3 secs: SPLIT_UPDATE event ignored
8689
* 0.4 secs: periodic fetch due to polling (/splitChanges)
87-
* 0.45 secs: periodic fetch due to polling (/mySegments/*)
88-
* 0.5 secs: Streaming up (OCCUPANCY event) -> syncAll (/splitChanges, /mySegments/nicolas)
89-
* 0.55 secs: create a new client while streaming -> initial fetch (/mySegments/marcio), auth, SSE connection and syncAll (/splitChanges, /mySegments/nicolas, /mySegments/marcio)
90+
* 0.45 secs: periodic fetch due to polling (/my(Large)Segments/*)
91+
* 0.5 secs: Streaming up (OCCUPANCY event) -> syncAll (/splitChanges, /my(Large)Segments/nicolas)
92+
* 0.55 secs: create a new client while streaming -> initial fetch (/my(Large)Segments/marcio), auth, SSE connection and syncAll (/splitChanges, /my(Large)Segments/nicolas, /my(Large)Segments/marcio)
9093
* 0.6 secs: SPLIT_UPDATE event -> /splitChanges
91-
* 0.7 secs: Streaming down (CONTROL event) -> fetch due to fallback to polling (/splitChanges, /mySegments/nicolas, /mySegments/marcio)
94+
* 0.7 secs: Streaming down (CONTROL event) -> fetch due to fallback to polling (/splitChanges, /my(Large)Segments/nicolas, /my(Large)Segments/marcio)
9295
* 0.8 secs: MY_SEGMENTS_UPDATE event ignored
9396
* 0.9 secs: periodic fetch due to polling (/splitChanges)
94-
* 0.95 secs: periodic fetch due to polling (/mySegments/nicolas, /mySegments/marcio, /mySegments/facundo)
95-
* 1.0 secs: Streaming up (CONTROL event) -> syncAll (/splitChanges, /mySegments/nicolas, /mySegments/marcio, /mySegments/facundo)
97+
* 0.95 secs: periodic fetch due to polling (/my(Large)Segments/nicolas, /my(Large)Segments/marcio, /my(Large)Segments/facundo)
98+
* 1.0 secs: Streaming up (CONTROL event) -> syncAll (/splitChanges, /my(Large)Segments/nicolas, /my(Large)Segments/marcio, /my(Large)Segments/facundo)
9699
* 1.1 secs: MY_SEGMENTS_UPDATE event -> /mySegments/nicolas
97-
* 1.2 secs: Streaming down (CONTROL event) -> fetch due to fallback to polling (/splitChanges, /mySegments/nicolas, /mySegments/marcio, /mySegments/facundo)
100+
* 1.2 secs: Streaming down (CONTROL event) -> fetch due to fallback to polling (/splitChanges, /my(Large)Segments/nicolas, /my(Large)Segments/marcio, /my(Large)Segments/facundo)
98101
* 1.3 secs: STREAMING_RESET control event -> auth, SSE connection, syncAll and stop polling
99102
* 1.5 secs: STREAMING_RESET control event -> auth, SSE connection, syncAll
100103
* 1.6 secs: Streaming closed (CONTROL STREAMING_DISABLED event) -> fetch due to fallback to polling (/splitChanges, /mySegments/nicolas, /mySegments/marcio, /mySegments/facundo)
101-
* 1.8 secs: periodic fetch due to polling (/splitChanges): due to update without segments, mySegments are not fetched
104+
* 1.8 secs: periodic fetch due to polling (/splitChanges)
105+
* 1.85 secs: periodic fetch due to polling (/myLargeSegments/*). /mySegments/* are not fetched due to update without segments
102106
* 2.0 secs: periodic fetch due to polling (/splitChanges)
103107
* 2.1 secs: destroy client
104108
*/
105-
export function testFallbacking(fetchMock, assert) {
109+
export function testFallback(fetchMock, assert) {
106110
assert.plan(20);
107111
fetchMock.reset();
108112

@@ -213,6 +217,10 @@ export function testFallbacking(fetchMock, assert) {
213217
return { status: 200, body: authPushEnabledNicolas };
214218
});
215219

220+
// MyLargeSegments are fetched one more time than MySegments due to smart pausing of MySegments sync at the end of the test
221+
fetchMock.get({ url: url(settings, '/myLargeSegments/nicolas%40split.io'), repeat: 14 }, { status: 200, body: { myLargeSegments: [] } });
222+
fetchMock.get({ url: url(settings, '/myLargeSegments/marcio%40split.io'), repeat: 10 }, { status: 200, body: { myLargeSegments: [] } });
223+
216224
// initial split and mySegment sync
217225
fetchMock.getOnce(url(settings, '/splitChanges?s=1.1&since=-1'), { status: 200, body: splitChangesMock1 });
218226
fetchMock.getOnce(url(settings, '/mySegments/nicolas%40split.io'), { status: 200, body: mySegmentsNicolasMock1 });

src/__tests__/browserSuites/push-refresh-token.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function testRefreshToken(fetchMock, assert) {
5757
sseCount++;
5858
switch (sseCount) {
5959
case 1:
60-
assert.true(nearlyEqual(Date.now() - start, 0), 'first connection is created inmediatelly');
60+
assert.true(nearlyEqual(Date.now() - start, 0), 'first connection is created immediately');
6161
break;
6262
case 2:
6363
assert.true(nearlyEqual(Date.now() - start, MILLIS_REFRESH_TOKEN + MILLIS_CONNDELAY), 'second connection is created with a delay');

src/__tests__/browserSuites/readiness.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default function (fetchMock, assert) {
6262
});
6363
});
6464

65-
assert.test(t => { // Timeout test, we have retries but mySegmnets takes too long
65+
assert.test(t => { // Timeout test, we have retries but mySegments takes too long
6666
const testUrls = {
6767
sdk: 'https://sdk.baseurl/readinessSuite2',
6868
events: 'https://events.baseurl/readinessSuite2'

src/__tests__/browserSuites/telemetry.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default async function telemetryBrowserSuite(fetchMock, t) {
7676

7777
// @TODO check if iDe value is correct
7878
assert.deepEqual(data, {
79-
mE: {}, hE: { sp: { 500: 1 }, ms: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 31, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
79+
mE: {}, hE: { sp: { 500: 1 }, ms: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 32, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
8080
}, 'metrics/usage JSON payload should be the expected');
8181

8282
finish.next();
@@ -96,7 +96,7 @@ export default async function telemetryBrowserSuite(fetchMock, t) {
9696
// @TODO check if iDe value is correct
9797
assert.deepEqual(data, {
9898
mL: {}, mE: {}, hE: {}, hL: {}, // errors and latencies were popped
99-
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 31, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
99+
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 32, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
100100
}, '2nd metrics/usage JSON payload should be the expected');
101101
return 200;
102102
});

src/__tests__/mocks/splitchanges.since.-1.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,75 @@
11
{
22
"splits": [
3+
{
4+
"orgId": null,
5+
"environment": null,
6+
"trafficTypeId": null,
7+
"trafficTypeName": null,
8+
"name": "in_large_segment",
9+
"seed": -1984784937,
10+
"status": "ACTIVE",
11+
"killed": false,
12+
"defaultTreatment": "no",
13+
"conditions": [
14+
{
15+
"matcherGroup": {
16+
"combiner": "AND",
17+
"matchers": [
18+
{
19+
"keySelector": {
20+
"trafficType": "user",
21+
"attribute": null
22+
},
23+
"matcherType": "IN_LARGE_SEGMENT",
24+
"negate": false,
25+
"userDefinedSegmentMatcherData": {
26+
"segmentName": "harnessians"
27+
},
28+
"whitelistMatcherData": null,
29+
"unaryNumericMatcherData": null,
30+
"betweenMatcherData": null,
31+
"unaryStringMatcherData": null
32+
}
33+
]
34+
},
35+
"partitions": [
36+
{
37+
"treatment": "yes",
38+
"size": 100
39+
}
40+
]
41+
},
42+
{
43+
"matcherGroup": {
44+
"combiner": "AND",
45+
"matchers": [
46+
{
47+
"keySelector": {
48+
"trafficType": "user",
49+
"attribute": null
50+
},
51+
"matcherType": "IN_LARGE_SEGMENT",
52+
"negate": false,
53+
"userDefinedSegmentMatcherData": {
54+
"segmentName": "splitters"
55+
},
56+
"whitelistMatcherData": null,
57+
"unaryNumericMatcherData": null,
58+
"betweenMatcherData": null,
59+
"unaryStringMatcherData": null
60+
}
61+
]
62+
},
63+
"partitions": [
64+
{
65+
"treatment": "yes",
66+
"size": 100
67+
}
68+
]
69+
}
70+
],
71+
"configurations": {}
72+
},
373
{
474
"orgId": null,
575
"environment": null,

src/__tests__/nodeSuites/push-fallbacking.spec.js renamed to src/__tests__/nodeSuites/push-fallback.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import { settingsFactory } from '../../settings';
3535
const key = 'nicolas@split.io';
3636

3737
const baseUrls = {
38-
sdk: 'https://sdk.push-fallbacking/api',
39-
events: 'https://events.push-fallbacking/api',
40-
auth: 'https://auth.push-fallbacking/api'
38+
sdk: 'https://sdk.push-fallback/api',
39+
events: 'https://events.push-fallback/api',
40+
auth: 'https://auth.push-fallback/api'
4141
};
4242
const config = {
4343
core: {
@@ -96,7 +96,7 @@ const MILLIS_DESTROY = MILLIS_STREAMING_DISABLED_CONTROL + settings.scheduler.fe
9696
* 2.1 secs: periodic fetch due to polling (/segmentChanges/*)
9797
* 2.1 secs: destroy client
9898
*/
99-
export function testFallbacking(fetchMock, assert) {
99+
export function testFallback(fetchMock, assert) {
100100
assert.plan(17);
101101
fetchMock.reset();
102102
__setEventSource(EventSourceMock);

src/__tests__/nodeSuites/push-refresh-token.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function testRefreshToken(fetchMock, assert) {
5757
sseCount++;
5858
switch (sseCount) {
5959
case 1:
60-
assert.true(nearlyEqual(Date.now() - start, 0), 'first connection is created inmediatelly');
60+
assert.true(nearlyEqual(Date.now() - start, 0), 'first connection is created immediately');
6161
break;
6262
case 2:
6363
assert.true(nearlyEqual(Date.now() - start, MILLIS_REFRESH_TOKEN + MILLIS_CONNDELAY), 'second connection is created with a delay');

src/__tests__/nodeSuites/telemetry.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default async function telemetryNodejsSuite(key, fetchMock, assert) {
6666

6767
// @TODO check if iDe value is correct
6868
assert.deepEqual(data, {
69-
mE: {}, hE: { sp: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 31, seC: 3, skC: 3, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
69+
mE: {}, hE: { sp: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 32, seC: 3, skC: 3, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
7070
}, 'metrics/usage JSON payload should be the expected');
7171

7272
finish.next();
@@ -85,7 +85,7 @@ export default async function telemetryNodejsSuite(key, fetchMock, assert) {
8585
// @TODO check if iDe value is correct
8686
assert.deepEqual(data, {
8787
mL: {}, mE: {}, hE: {}, hL: {}, // errors and latencies were popped
88-
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 31, seC: 3, skC: 3, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
88+
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 32, seC: 3, skC: 3, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
8989
}, '2nd metrics/usage JSON payload should be the expected');
9090
return 200;
9191
});

0 commit comments

Comments
 (0)