Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #119 from launchdarkly/eb/ch30067/store-tests
Browse files Browse the repository at this point in the history
add feature store test for prefix option
  • Loading branch information
eli-darkly authored Jan 16, 2019
2 parents 1c3f4a5 + 9b206f9 commit 0ce5dc9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions test/feature_store_test_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 () => {
Expand Down
8 changes: 6 additions & 2 deletions test/redis_feature_store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0ce5dc9

Please sign in to comment.