Skip to content

Commit 85578eb

Browse files
Update redis, listener and manager tests
1 parent 3db4e45 commit 85578eb

File tree

6 files changed

+48
-26
lines changed

6 files changed

+48
-26
lines changed

src/__tests__/browserSuites/impressions-listener.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,21 @@ export default function (assert) {
5757
keyName: 'marcio@split.io',
5858
treatment: 'no',
5959
bucketingKey: 'impr_bucketing_2',
60-
label: 'default rule'
60+
label: 'default rule',
61+
pt: undefined
6162
};
6263

6364
assert.equal(listener.logImpression.callCount, 4, 'Impression listener logImpression method should be called after we call client.getTreatment, once per each impression generated.');
64-
assert.true(listener.logImpression.getCall(0).calledWithMatch({
65+
assert.true(listener.logImpression.getCall(0).calledWithExactly({
6566
impression: {
6667
feature: 'hierarchical_splits_test',
6768
keyName: 'nicolas@split.io',
6869
treatment: 'on',
70+
time: listener.logImpression.getCall(0).args[0].impression.time,
6971
bucketingKey: undefined,
7072
label: 'expected label',
73+
changeNumber: 2828282828,
74+
pt: undefined
7175
},
7276
attributes: undefined,
7377
...metaData

src/__tests__/browserSuites/manager.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export default async function (settings, fetchMock, assert) {
4141
'treatments': map(mockSplits.splits[index].conditions[0].partitions, partition => partition.treatment),
4242
'configs': mockSplits.splits[index].configurations || {},
4343
'sets': mockSplits.splits[index].sets || [],
44-
'defaultTreatment': mockSplits.splits[index].defaultTreatment
44+
'defaultTreatment': mockSplits.splits[index].defaultTreatment,
45+
'trackImpressions': true
4546
});
4647

4748
assert.equal(manager.split('non_existent'), null, 'Trying to get a manager.split() of a Split that does not exist returns null.');

src/__tests__/consumer/node_redis.spec.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const expectedImpressionCount = [
6161
];
6262

6363
const expectedSplitName = 'hierarchical_splits_testing_on';
64-
const expectedSplitView = { name: 'hierarchical_splits_testing_on', trafficType: 'user', killed: false, changeNumber: 1487277320548, treatments: ['on', 'off'], configs: {}, sets: [], defaultTreatment: 'off' };
64+
const expectedSplitView = { name: 'hierarchical_splits_testing_on', trafficType: 'user', killed: false, changeNumber: 1487277320548, treatments: ['on', 'off'], configs: {}, sets: [], defaultTreatment: 'off', trackImpressions: true };
6565

6666
const MOCKS = {
6767
'': 'redis-commands',
@@ -150,11 +150,12 @@ tape('Node.js Redis', function (t) {
150150

151151
assert.equal(await client.getTreatment('UT_Segment_member', 'always-on'), 'on', 'Evaluations using Redis storage should be correct.');
152152

153-
// Below splits were added manually to the redis_mock.json file.
153+
// Below feature flags were added manually to the redis_mock.json file.
154154
// They are all_keys (always evaluate to on) which depend from always-on split. the _on/off is what treatment they are expecting there.
155155
assert.equal(await client.getTreatment('UT_Segment_member', 'hierarchical_splits_testing_on'), 'on', 'Evaluations using Redis storage should be correct.');
156156
assert.equal(await client.getTreatment('UT_Segment_member', 'hierarchical_splits_testing_off'), 'off', 'Evaluations using Redis storage should be correct.');
157157
assert.equal(await client.getTreatment('UT_Segment_member', 'hierarchical_splits_testing_on_negated'), 'off', 'Evaluations using Redis storage should be correct.');
158+
assert.equal(await client.getTreatment('other_key', 'always-on-track-impressions-false'), 'on', 'Evaluations using Redis storage should be correct.');
158159

159160
assert.equal(typeof client.track().then, 'function', 'Track calls should always return a promise on Redis mode, even when parameters are incorrect.');
160161

@@ -163,35 +164,46 @@ tape('Node.js Redis', function (t) {
163164

164165
// Manager methods
165166
const splitNames = await manager.names();
166-
assert.equal(splitNames.length, 25, 'manager `names` method returns the list of split names asynchronously');
167+
assert.equal(splitNames.length, 26, 'manager `names` method returns the list of split names asynchronously');
167168
assert.equal(splitNames.indexOf(expectedSplitName) > -1, true, 'list of split names should contain expected splits');
168169
assert.deepEqual(await manager.split(expectedSplitName), expectedSplitView, 'manager `split` method returns the split view of the given split name asynchronously');
169170
const splitViews = await manager.splits();
170-
assert.equal(splitViews.length, 25, 'manager `splits` method returns the list of split views asynchronously');
171+
assert.equal(splitViews.length, 26, 'manager `splits` method returns the list of split views asynchronously');
171172
assert.deepEqual(splitViews.find(splitView => splitView.name === expectedSplitName), expectedSplitView, 'manager `split` method returns the split view of the given split name asynchronously');
172173

173174
await client.ready(); // promise already resolved
174175
await client.destroy();
175176

176-
// Validate stored impressions and events
177-
exec(`echo "LLEN ${config.storage.prefix}.SPLITIO.impressions \n LLEN ${config.storage.prefix}.SPLITIO.events" | redis-cli -p ${redisPort}`, (error, stdout) => {
178-
if (error) assert.fail('Redis server should be reachable');
177+
// Validate Impression Counts and Unique Keys for 'always-on-track-impressions-false'
178+
exec(`echo "HGETALL ${config.storage.prefix}.SPLITIO.impressions.count" | redis-cli -p ${redisPort}`, async (error, stdout) => {
179+
const trackedImpressionCounts = stdout.split('\n').filter(line => line !== '');
180+
assert.deepEqual(trackedImpressionCounts, [`always-on-track-impressions-false::${truncateTimeFrame(timeFrame)}`, '1',], 'Tracked impression counts should be stored in Redis TODO');
179181

180-
const trackedImpressionsAndEvents = stdout.split('\n').filter(line => line !== '').map(line => parseInt(line));
181-
assert.deepEqual(trackedImpressionsAndEvents, [TOTAL_RAW_IMPRESSIONS, TOTAL_EVENTS], 'Tracked impressions and events should be stored in Redis');
182+
exec(`echo "LRANGE ${config.storage.prefix}.SPLITIO.uniquekeys 0 20" | redis-cli -p ${redisPort}`, async (error, stdout) => {
183+
const storedUniqueKeys = stdout.split('\n').filter(line => line !== '').map(JSON.parse);
184+
assert.deepEqual(storedUniqueKeys, [{ 'f': 'always-on-track-impressions-false', 'ks': ['other_key'] }], 'Unique keys should be stored in Redis TODO');
182185

183-
// Validate stored telemetry
184-
exec(`echo "HLEN ${config.storage.prefix}.SPLITIO.telemetry.latencies \n HLEN ${config.storage.prefix}.SPLITIO.telemetry.exceptions \n HGET ${config.storage.prefix}.SPLITIO.telemetry.init nodejs-${version}/${HOSTNAME_VALUE}/${IP_VALUE}" | redis-cli -p ${redisPort}`, (error, stdout) => {
185-
if (error) assert.fail('Redis server should be reachable');
186+
// Validate stored impressions and events
187+
exec(`echo "LLEN ${config.storage.prefix}.SPLITIO.impressions \n LLEN ${config.storage.prefix}.SPLITIO.events" | redis-cli -p ${redisPort}`, (error, stdout) => {
188+
if (error) assert.fail('Redis server should be reachable');
186189

187-
const [latencies, exceptions, configValue] = stdout.split('\n').filter(line => line !== '').map(JSON.parse);
190+
const trackedImpressionsAndEvents = stdout.split('\n').filter(line => line !== '').map(line => parseInt(line));
191+
assert.deepEqual(trackedImpressionsAndEvents, [TOTAL_RAW_IMPRESSIONS, TOTAL_EVENTS], 'Tracked impressions and events should be stored in Redis');
188192

189-
assert.true(latencies > 0, 'There are stored latencies');
190-
assert.true(exceptions === 0, 'There aren\'t stored exceptions');
191-
assert.deepEqual(configValue, { oM: 1, st: 'redis', aF: 1, rF: 0 }, 'There is stored telemetry config');
193+
// Validate stored telemetry
194+
exec(`echo "HLEN ${config.storage.prefix}.SPLITIO.telemetry.latencies \n HLEN ${config.storage.prefix}.SPLITIO.telemetry.exceptions \n HGET ${config.storage.prefix}.SPLITIO.telemetry.init 'nodejs-${version}/${HOSTNAME_VALUE}/${IP_VALUE}'" | redis-cli -p ${redisPort}`, (error, stdout) => {
195+
if (error) assert.fail('Redis server should be reachable');
196+
197+
const [latencies, exceptions, configValue] = stdout.split('\n').filter(line => line !== '').map(JSON.parse);
192198

193-
// close server connection
194-
server.close().then(assert.end);
199+
assert.true(latencies > 0, 'There are stored latencies');
200+
assert.true(exceptions === 0, 'There aren\'t stored exceptions');
201+
assert.deepEqual(configValue, { oM: 1, st: 'redis', aF: 1, rF: 0 }, 'There is stored telemetry config');
202+
203+
// close server connection
204+
server.close().then(assert.end);
205+
});
206+
});
195207
});
196208
});
197209
});
@@ -304,7 +316,7 @@ tape('Node.js Redis', function (t) {
304316
assert.deepEqual(trackedImpressionsAndEvents, [TOTAL_RAW_IMPRESSIONS - DEDUPED_IMPRESSIONS, TOTAL_EVENTS], 'Tracked impressions and events should be stored in Redis');
305317

306318
// Validate stored telemetry
307-
exec(`echo "HLEN ${config.storage.prefix}.SPLITIO.telemetry.latencies \n HLEN ${config.storage.prefix}.SPLITIO.telemetry.exceptions \n HGET ${config.storage.prefix}.SPLITIO.telemetry.init nodejs-${version}/${HOSTNAME_VALUE}/${IP_VALUE}" | redis-cli -p ${redisPort}`, (error, stdout) => {
319+
exec(`echo "HLEN ${config.storage.prefix}.SPLITIO.telemetry.latencies \n HLEN ${config.storage.prefix}.SPLITIO.telemetry.exceptions \n HGET ${config.storage.prefix}.SPLITIO.telemetry.init 'nodejs-${version}/${HOSTNAME_VALUE}/${IP_VALUE}'" | redis-cli -p ${redisPort}`, (error, stdout) => {
308320
if (error) assert.fail('Redis server should be reachable');
309321

310322
const [latencies, exceptions, configValue] = stdout.split('\n').filter(line => line !== '').map(JSON.parse);
@@ -406,7 +418,7 @@ tape('Node.js Redis', function (t) {
406418
assert.deepEqual(trackedImpressionsAndEvents, [0, TOTAL_EVENTS], 'No impressions are stored in Redis in NONE impressions mode');
407419

408420
// Validate stored telemetry
409-
exec(`echo "HLEN ${config.storage.prefix}.SPLITIO.telemetry.latencies \n HLEN ${config.storage.prefix}.SPLITIO.telemetry.exceptions \n HGET ${config.storage.prefix}.SPLITIO.telemetry.init nodejs-${version}/${HOSTNAME_VALUE}/${IP_VALUE}" | redis-cli -p ${redisPort}`, (error, stdout) => {
421+
exec(`echo "HLEN ${config.storage.prefix}.SPLITIO.telemetry.latencies \n HLEN ${config.storage.prefix}.SPLITIO.telemetry.exceptions \n HGET ${config.storage.prefix}.SPLITIO.telemetry.init 'nodejs-${version}/${HOSTNAME_VALUE}/${IP_VALUE}'" | redis-cli -p ${redisPort}`, (error, stdout) => {
410422
if (error) assert.fail('Redis server should be reachable');
411423

412424
const [latencies, exceptions, configValue] = stdout.split('\n').filter(line => line !== '').map(JSON.parse);

0 commit comments

Comments
 (0)