-
Notifications
You must be signed in to change notification settings - Fork 58
feat: add throttle and delay to connect #478
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d1cf8c9
feat: add throttle and delay to connect
DominicGBauer 241bb81
fix: name change
DominicGBauer 69811b7
chore: add changeset
DominicGBauer 274736a
feat: add options to web
DominicGBauer 823970f
chore: improve comment
DominicGBauer 961c961
chore: pr feedback
DominicGBauer 78d21c0
chore: remove optional flag
DominicGBauer 769b46f
chore: revert previous changes
DominicGBauer 6c4db3b
chore: avoid breaking change
DominicGBauer f4e5e88
chore: add changes
DominicGBauer a366e3d
chore: remove comments
DominicGBauer c332fdd
chore: pr feedback
DominicGBauer 0e6d380
chore: update tests
DominicGBauer 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 hidden or 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,6 @@ | ||
--- | ||
'@powersync/react-native': minor | ||
'@powersync/common': minor | ||
--- | ||
|
||
Add `retryDelayMs` and `crudUploadThrottleMs` to `connect` so that the values can be dynamically changed upon reconnecting. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,122 @@ | ||
import { describe, it, expect, beforeEach, vi } from 'vitest' | ||
import { PowerSyncDatabase, SharedWebStreamingSyncImplementation, WebStreamingSyncImplementation } from '../../../src' | ||
import { SSRStreamingSyncImplementation } from '../../../src/db/sync/SSRWebStreamingSyncImplementation' | ||
import { testSchema } from '../../utils/testDb' | ||
|
||
|
||
vi.mock('../../../src/db/sync/WebStreamingSyncImplementation') | ||
vi.mock('../../../src/db/sync/SharedWebStreamingSyncImplementation') | ||
vi.mock('../../../src/db/sync/SSRWebStreamingSyncImplementation') | ||
|
||
describe('PowerSyncDatabase - generateSyncStreamImplementation', () => { | ||
const mockConnector = { | ||
uploadData: vi.fn(), | ||
fetchCredentials: vi.fn() | ||
} | ||
|
||
beforeEach(() => { | ||
vi.resetAllMocks() | ||
}) | ||
|
||
it('uses SSRStreamingSyncImplementation when ssrMode is true', async () => { | ||
// This is to prevent a false positive from the unhandled rejection | ||
// of using SSR in this test. | ||
const handler = (event: PromiseRejectionEvent) => { | ||
event.preventDefault() | ||
} | ||
window.addEventListener('unhandledrejection', handler) | ||
|
||
const db = new PowerSyncDatabase({ | ||
schema: testSchema, | ||
database: { | ||
dbFilename: 'test.db' | ||
}, | ||
flags: { | ||
ssrMode: true, | ||
}, | ||
retryDelayMs: 1000, | ||
crudUploadThrottleMs: 2000 | ||
}) | ||
|
||
db['generateSyncStreamImplementation'](mockConnector) | ||
expect(SSRStreamingSyncImplementation).toHaveBeenCalled() | ||
|
||
await setTimeout(() => window.removeEventListener('unhandledrejection', handler), 1) | ||
}) | ||
|
||
it('uses SharedWebStreamingSyncImplementation when enableMultiTabs is true', () => { | ||
const db = new PowerSyncDatabase({ | ||
schema: testSchema, | ||
database: { dbFilename: 'test.db' }, | ||
flags: { enableMultiTabs: true } | ||
}) | ||
db['generateSyncStreamImplementation'](mockConnector) | ||
expect(SharedWebStreamingSyncImplementation).toHaveBeenCalled() | ||
}) | ||
|
||
it('handles option overrides', () => { | ||
const db = new PowerSyncDatabase({ | ||
schema: testSchema, | ||
database: { | ||
dbFilename: 'test.db' | ||
}, | ||
flags: { | ||
ssrMode: false, | ||
enableMultiTabs: false, | ||
}, | ||
crudUploadThrottleMs: 1000 | ||
}) | ||
|
||
db['generateSyncStreamImplementation'](mockConnector, { crudUploadThrottleMs: 20000, retryDelayMs: 50000 }) | ||
expect(WebStreamingSyncImplementation).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
retryDelayMs: 50000, | ||
crudUploadThrottleMs: 20000 | ||
}) | ||
) | ||
}) | ||
|
||
it('handles partial option overrides', () => { | ||
const db = new PowerSyncDatabase({ | ||
schema: testSchema, | ||
database: { | ||
dbFilename: 'test.db' | ||
}, | ||
flags: { | ||
ssrMode: false, | ||
enableMultiTabs: false, | ||
}, | ||
retryDelayMs: 1000, | ||
crudUploadThrottleMs: 2000 | ||
}) | ||
|
||
db['generateSyncStreamImplementation'](mockConnector, { retryDelayMs: 50000 }) | ||
expect(WebStreamingSyncImplementation).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
retryDelayMs: 50000, | ||
}) | ||
) | ||
}) | ||
|
||
// This test can be removed once retryDelay is removed and entirely replaced with retryDelayMs | ||
it('works when using deprecated retryDelay instead of retryDelayMs', () => { | ||
const db = new PowerSyncDatabase({ | ||
schema: testSchema, | ||
database: { | ||
dbFilename: 'test.db' | ||
}, | ||
flags: { | ||
ssrMode: false, | ||
enableMultiTabs: false, | ||
}, | ||
retryDelay: 11100, | ||
}) | ||
|
||
db['generateSyncStreamImplementation'](mockConnector) | ||
expect(WebStreamingSyncImplementation).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
retryDelayMs: 11100, | ||
}) | ||
) | ||
}) | ||
}) |
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.
Uh oh!
There was an error while loading. Please reload this page.