diff --git a/package-lock.json b/package-lock.json index 3b99cfd..b69f93f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ldclient-node", - "version": "5.6.2", + "version": "5.7.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/test/feature_store_test_base.js b/test/feature_store_test_base.js index 911f1da..1afe1dd 100644 --- a/test/feature_store_test_base.js +++ b/test/feature_store_test_base.js @@ -6,13 +6,13 @@ const { asyncify } = require('./async_utils'); // caching disabled. // // Parameters: -// - makeStore(): creates an instance of the feature store. +// - makeStore(): creates an instance of the feature store // - clearExistingData(callback): if specified, will be called before each test to clear any -// storage that the store instances may be sharing. -// - isCached: true if the instances returned by makeStore() have caching enabled. If -// applicable, +// storage that the store instances may be sharing; this also implies that the feature store +// - isCached: true if the instances returned by makeStore() have caching enabled. +// - makeStoreWithPrefix(prefix): creates an uncached instance of the store with a key prefix -function baseFeatureStoreTests(makeStore, clearExistingData, isCached) { +function baseFeatureStoreTests(makeStore, clearExistingData, isCached, makeStoreWithPrefix) { var feature1 = { key: 'foo', version: 10 @@ -97,6 +97,21 @@ function baseFeatureStoreTests(makeStore, clearExistingData, isCached) { testInitStateDetection('can detect if another instance has initialized the store, even with empty data', { features: {} }); + + if (makeStoreWithPrefix) { + it('is independent from other instances with different prefixes', async () => { + var flag = { key: 'flag', version: 1 }; + var storeA = makeStoreWithPrefix('a'); + await asyncify(cb => storeA.init({ features: { flag: flag } }, cb)); + var storeB = makeStoreWithPrefix('b'); + await asyncify(cb => storeB.init({ features: { } }, cb)); + var storeB1 = makeStoreWithPrefix('b'); // this ensures we're not just reading cached data + var item = await asyncify(cb => storeB1.get(dataKind.features, 'flag', cb)); + expect(item).toBe(null); + item = await asyncify(cb => storeA.get(dataKind.features, 'flag', cb)); + expect(item).toEqual(flag); + }); + } } it('gets existing feature', async () => { diff --git a/test/redis_feature_store-test.js b/test/redis_feature_store-test.js index 1ba8837..8c790a6 100644 --- a/test/redis_feature_store-test.js +++ b/test/redis_feature_store-test.js @@ -9,19 +9,23 @@ describe('RedisFeatureStore', function() { var extraRedisClient = redis.createClient(redisOpts); function makeCachedStore() { - return new RedisFeatureStore(redisOpts, 30); + return new RedisFeatureStore(redisOpts, 30); } function makeUncachedStore() { return new RedisFeatureStore(redisOpts, 0); } + function makeStoreWithPrefix(prefix) { + return new RedisFeatureStore(redisOpts, 0, prefix); + } + function clearExistingData(callback) { extraRedisClient.flushdb(callback); } testBase.baseFeatureStoreTests(makeCachedStore, clearExistingData, true); - testBase.baseFeatureStoreTests(makeUncachedStore, clearExistingData, false); + testBase.baseFeatureStoreTests(makeUncachedStore, clearExistingData, false, makeStoreWithPrefix); testBase.concurrentModificationTests(makeUncachedStore, function(hook) {