Skip to content

Commit 87b556d

Browse files
test: update Redis tests to assert fallback treatments
1 parent 299cfc8 commit 87b556d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/__tests__/consumer/node_redis.spec.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,14 @@ tape('Node.js Redis', function (t) {
550550
t.test('Connection error', assert => {
551551
initializeRedisServer()
552552
.then((server) => {
553-
const sdk = SplitFactory(config);
553+
const sdk = SplitFactory({
554+
...config,
555+
fallbackTreatments: {
556+
byFlag: {
557+
'always-on': 'control_always_on'
558+
}
559+
}
560+
});
554561
const client = sdk.client();
555562

556563
client.once(client.Event.SDK_READY_TIMED_OUT, assert.fail);
@@ -585,7 +592,7 @@ tape('Node.js Redis', function (t) {
585592
assert.equal(await client.getTreatment('UT_Segment_member', 'UT_NOT_SET_MATCHER', {
586593
permissions: ['not_matching']
587594
}), 'control', 'In the event of a Redis error like a disconnection, getTreatments should not hang but resolve to "control".');
588-
assert.equal(await client.getTreatment('UT_Segment_member', 'always-on'), 'control', 'In the event of a Redis error like a disconnection, getTreatments should not hang but resolve to "control".');
595+
assert.equal(await client.getTreatment('UT_Segment_member', 'always-on'), 'control_always_on', 'In the event of a Redis error like a disconnection, getTreatments should not hang but resolve to fallback treatment or "control".');
589596

590597
assert.false(await client.track('nicolas@split.io', 'user', 'test.redis.event', 18), 'In the event of a Redis error like a disconnection, track should resolve to false.');
591598

ts-tests/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ promise = client.destroy();
263263
promise = SDK.destroy();
264264
// @TODO not public yet
265265
// promise = client.flush();
266-
const promiseWhenReadyFromCache: Promise<boolean> = client.whenReadyFromCache();
266+
let promiseWhenReadyFromCache: Promise<boolean> = client.whenReadyFromCache();
267267

268268
// Get readiness status
269269
let status: SplitIO.ReadinessStatus = client.getStatus();
@@ -378,10 +378,15 @@ nodeEventEmitter = asyncClient;
378378

379379
// Ready, destroy and flush (same as for sync client, just for interface checking)
380380
promise = asyncClient.ready();
381+
promise = asyncClient.whenReady();
381382
promise = asyncClient.destroy();
382383
promise = AsyncSDK.destroy();
383384
// @TODO not public yet
384385
// promise = asyncClient.flush();
386+
promiseWhenReadyFromCache = asyncClient.whenReadyFromCache();
387+
388+
// Get readiness status
389+
status = asyncClient.getStatus();
385390

386391
// We can call getTreatment but always with a key.
387392
asyncTreatment = asyncClient.getTreatment(splitKey, 'mySplit');

0 commit comments

Comments
 (0)