-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added persistent settings store for dynamic settings configuration #1559
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
'use strict'; | ||
|
||
var PersistentSettingsStore = require('../src/PersistentSettingsStore').default; | ||
var DatabaseAdapter = require('../src/DatabaseAdapter'); | ||
var appId = 'test'; | ||
var collectionPrefix = 'test_'; | ||
var store; | ||
var settingsCollection; | ||
|
||
describe('PersistentSettingsStore', function () { | ||
beforeEach(function () { | ||
store = PersistentSettingsStore({ | ||
freshness: 0.1 | ||
}, { | ||
defined: 0 | ||
}); | ||
}); | ||
|
||
describe('mocked db', function () { | ||
beforeEach(function () { | ||
settingsCollection = jasmine.createSpyObj('settingsCollection', ['find', 'upsertOne']); | ||
settingsCollection.find.and.returnValue(Promise.resolve([])); | ||
settingsCollection.upsertOne.and.returnValue(Promise.resolve()); | ||
|
||
spyOn(DatabaseAdapter, 'getDatabaseConnection').and.returnValue({ | ||
adaptiveCollection: _ => { | ||
return Promise.resolve(settingsCollection); | ||
} | ||
}); | ||
}); | ||
|
||
it('does not persist locked settings', function() { | ||
store.set(appId, { | ||
applicationId: appId | ||
}); | ||
|
||
expect(store.get(appId, 'persisted').applicationId).toBeUndefined; | ||
expect(store.get(appId, 'locked').applicationId).toEqual(appId); | ||
}); | ||
|
||
it('does not persist defined settings by default', function() { | ||
store.set(appId, { | ||
defined: 0 | ||
}); | ||
|
||
expect(store.get(appId, 'persisted').defined).toBeUndefined; | ||
expect(store.get(appId, 'locked').defined).toBeDefined; | ||
}); | ||
|
||
it('persists defined settings if lockDefinedSettings false', function() { | ||
store = PersistentSettingsStore({ | ||
lockDefinedSettings: false | ||
}, { | ||
defined: 0 | ||
}); | ||
|
||
store.set(appId, { | ||
defined: 0 | ||
}); | ||
|
||
expect(store.get(appId, 'persisted').defined).toBeDefined; | ||
expect(store.get(appId, 'locked').defined).toBeUndefined; | ||
}); | ||
|
||
it('does not allow modification of locked settings', function() { | ||
store.set(appId, { | ||
defined: 0 | ||
}); | ||
|
||
store.get(appId).defined = 2; | ||
|
||
expect(store.get(appId).defined).toEqual(0); | ||
}); | ||
|
||
it('allows modification of persisted settings', function() { | ||
store.set(appId, { | ||
modifiable: 0 | ||
}); | ||
|
||
store.get(appId).modifiable = 2; | ||
expect(store.get(appId).modifiable).toEqual(2); | ||
}); | ||
|
||
it('respects freshness option', function(done) { | ||
// freshness 100 ms | ||
store.set(appId, { | ||
modifiable: 0 | ||
}); | ||
|
||
function get() { | ||
store.get(appId); | ||
} | ||
setTimeout(get, 50); | ||
// freshness expires | ||
setTimeout(get, 150); | ||
setTimeout(get, 200); | ||
// freshness expires | ||
setTimeout(get, 300) | ||
setTimeout(function () { | ||
// three calls: one for initial pull, two from expired freshness | ||
expect(settingsCollection.find.calls.count()).toEqual(3); | ||
done(); | ||
}, 350); | ||
}); | ||
|
||
it('pushes on setting change', function(done) { | ||
store.set(appId, { | ||
applicationId: appId, | ||
modifiable: 0 | ||
}); | ||
|
||
setTimeout(function () { | ||
store.get(appId).modifiable = 2; | ||
}, 100); | ||
|
||
setTimeout(function () { | ||
var calls = settingsCollection.upsertOne.calls; | ||
expect(calls.count()).toEqual(2); | ||
expect(calls.argsFor(0)[1]).toEqual({ | ||
applicationId: appId, | ||
persisted: { | ||
modifiable: 0 | ||
} | ||
}); | ||
expect(calls.argsFor(1)[1]).toEqual({ | ||
$set: { | ||
'persisted.modifiable': 2 | ||
} | ||
}); | ||
done(); | ||
}, 200); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the intended behavior upon server restart?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If settingsCacheOptions is false there is no persistence. Otherwise, cache.apps.set() will trigger a pull from the database, update persisted settings with whatever is returned, then push to the database. However, locked & defined properties won't be updated even if they exist in the database because I attach a dummy setter to those properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so how do you load a new configuration, like a new masterKey or update a property that is locked or defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defined settings are modifiable if lockDefinedSettings is false (so they will be overwritten by their persisted values).
Locked settings (like masterKey) are settings where I wasn't sure how to approach modifying them without a restart due to side effects. For example, if you change the masterKey from the parse dashboard all the sudden your experience is broken as you can't connect to the server anymore because your masterKey in the parse-dashboard-config is invalid.
The only way to update these locked settings is in the code configuration you pass to the parse server constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the other problem is the risk of error, rewriting from the passed options, and losing the changes (like masterKey) that has been changed from the dashboard.