-
Notifications
You must be signed in to change notification settings - Fork 123
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
Protocol message to reset client state #1213
Merged
magnetised
merged 2 commits into
garry/vax-1710-feature-flag-to-turn-on-permissions-in-hard-mode
from
garry/vax-1817-protocol-message-to-reset-client-state
May 2, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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 |
---|---|---|
|
@@ -54,6 +54,11 @@ import { mergeEntries } from '../../src/satellite/merge' | |
import { MockSubscriptionsManager } from '../../src/satellite/shapes/manager' | ||
import { AuthState, insecureAuthToken } from '../../src/auth' | ||
import { ConnectivityStateChangeNotification } from '../../src/notifiers' | ||
import { | ||
SatClientCommand, | ||
SatClientCommand_ResetDatabase, | ||
SatClientCommand_ResetDatabase_Reason, | ||
} from '../../src/_generated/protocol/satellite' | ||
|
||
const parentRecord = { | ||
id: 1, | ||
|
@@ -2286,3 +2291,44 @@ test("don't snapshot after closing satellite process", async (t) => { | |
|
||
t.pass() | ||
}) | ||
|
||
test('SatClientCommand.ResetDatabase clears all data', async (t) => { | ||
const { client, satellite, adapter } = t.context | ||
const { runMigrations, authState, token } = t.context | ||
await runMigrations() | ||
const tablename = 'parent' | ||
|
||
// relations must be present at subscription delivery | ||
client.setRelations(relations) | ||
client.setRelationData(tablename, parentRecord) | ||
|
||
await startSatellite(satellite, authState, token) | ||
|
||
const shapeDef: Shape = { | ||
tablename, | ||
} | ||
|
||
satellite!.relations = relations | ||
const { synced } = await satellite.subscribe([shapeDef]) | ||
await synced | ||
await satellite._performSnapshot() | ||
const subscriptionCount = | ||
satellite.subscriptions.getFulfilledSubscriptions().length | ||
|
||
await client.commandCb!( | ||
SatClientCommand.fromPartial({ | ||
resetDatabase: SatClientCommand_ResetDatabase.fromPartial({ | ||
reason: SatClientCommand_ResetDatabase_Reason.PERMISSIONS_CHANGE, | ||
}), | ||
}) | ||
) | ||
|
||
const results = await adapter.query({ | ||
sql: 'SELECT * FROM main.parent', | ||
}) | ||
|
||
t.deepEqual(results, []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also check that the subscribed shapes are kept? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. rather than crowbar it in here though, I'll add it in a later pr and ping you. |
||
|
||
// make sure our existing subscriptions have been saved | ||
t.assert(satellite.previousShapeSubscriptions.length == subscriptionCount) | ||
}) |
Oops, something went wrong.
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.
nit: we unsubscribe from something
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.
agreed - I was just being consistent with the current unsubscribe function names e.g.
unsubscribeToAdditionalData
,unsubscribeToTransactions
,unsubscribeToRelations