-
Notifications
You must be signed in to change notification settings - Fork 0
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
fix: prevent chrome storage resolving before entries are set #126
base: main
Are you sure you want to change the base?
fix: prevent chrome storage resolving before entries are set #126
Conversation
chrome.storage.onChanged.removeListener(listener); | ||
applicationLogger.warn('Chrome storage write timeout for key:', key); | ||
resolve(); | ||
}, 1000); |
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.
One second is probably too long, but we also never expect to end up in this situation of needing the timeout. It's a precaution
(mockStorage.set as jest.Mock).mockResolvedValue(undefined); | ||
|
||
// Start the set operation | ||
const setPromise = storageMap.set(key, value); |
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.
This isn't exactly what I am hoping to test since the set operation isn't in progress, and I'm interested in testing that an entry hasn't been written yet between the time that the operation started and onChange was fired. I couldn't figure out how to write such a test.
|
||
public constructor(private storageEngine: IStringStorageEngine, private cooldownSeconds = 0) {} | ||
|
||
public isInitialized(): boolean { | ||
return this.initialized; | ||
} | ||
|
||
public isInProcessOfInitializing(): boolean { |
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.
TODO add isInProcessOfInitializing
to the IAsyncStore
interface
labels: mergeable
Fixes: #issue
Motivation and Context
We had a hypothesis in a debugging session that
await this.storage.set
may be resolving when the writing process starts, instead of when it finishes writing the fetched flags to storage and that this may be an idiosyncratic behavior of the Chrome storage implementation. If true, this could result in inconsistent, null assignments on application start if get assignment is called immediately afterawait init
Description
This is a draft of using an
isInProcessOfInitializing
method to wait before deciding if the store is usableHow has this been tested?