Skip to content

Commit

Permalink
Adding redis tests part1 for flagsets, this wont work without commons
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Zelaya authored and Nicolas Zelaya committed Nov 3, 2023
1 parent c45244a commit d13fdcc
Showing 1 changed file with 65 additions and 2 deletions.
67 changes: 65 additions & 2 deletions src/__tests__/consumer/node_redis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,24 @@ const expectedImpressionCount = [
`hierarchical_splits_testing_on_negated::${truncateTimeFrame(timeFrame)}`, '1',
];

const MOCKS = {
'': 'redis-commands',
'flag_sets': 'redis-commands-sets'
};

/**
* Initialize redis server and run a cli bash command to load redis with data to do the proper tests
*/
const initializeRedisServer = () => {
const initializeRedisServer = (mock = '') => {
// Simply pass the port that you want a Redis server to listen on.
const server = new RedisServer(redisPort);
const mockFileName = MOCKS[mock];

const promise = new Promise((resolve, reject) => {
server
.open()
.then(() => {
exec(`cat ./src/__tests__/mocks/redis-commands.txt | redis-cli -p ${redisPort}`, err => {
exec(`cat ./src/__tests__/mocks/${mockFileName}.txt | redis-cli -p ${redisPort}`, err => {
if (err) {
reject(server);
// node couldn't execute the command
Expand Down Expand Up @@ -632,4 +638,61 @@ tape('NodeJS Redis', function (t) {
server.close().then(assert.end);
});
});

t.test('Getting treatments with flag sets', assert => {
initializeRedisServer('flag_sets')
.then(async (server) => {
const sdk = SplitFactory(config);

const client = sdk.client();
await client.ready();

// @TODO: Working to remove this crap, debugging RedisAdapter queueing and why it doesnt like the pipeline exec.
setTimeout(async function () {


assert.deepEqual(
await client.getTreatmentsByFlagSet('nico@test', 'set_one'),
{ 'always-on': 'on', 'always-off': 'off' },
'Evaluations using Redis storage should be correct for a set.'
);

assert.deepEqual(
await client.getTreatmentsByFlagSet('nico@test', 'set_two'),
{ 'always-off': 'off', 'nico_not': 'off' },
'Evaluations using Redis storage should be correct for a set.'
);

assert.deepEqual(
await client.getTreatmentsByFlagSet('nico@test', 'set_invalid'),
{},
'Evaluations using Redis storage should properly handle all invalid sets.'
);

assert.deepEqual(
await client.getTreatmentsByFlagSets('nico@test', ['set_two', 'set_one']),
{ 'always-on': 'on', 'always-off': 'off', 'nico_not': 'off' },
'Evaluations using Redis storage should be correct for multiple sets.'
);

assert.deepEqual(
await client.getTreatmentsByFlagSets('nico@test', [243, null, 'set_two', 'set_one', 'invalid_set']),
{ 'always-on': 'on', 'always-off': 'off', 'nico_not': 'off' },
'Evaluations using Redis storage should be correct for multiple sets, discarding invalids.'
);

assert.deepEqual(
await client.getTreatmentsByFlagSets('nico@test', [243, null, 'invalid_set']),
{},
'Evaluations using Redis storage should properly handle all invalid sets.'
);

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

// close server connection
server.close().then(assert.end);
},1000);
});
});
});

0 comments on commit d13fdcc

Please sign in to comment.