Skip to content

Add more Recovery spec tests #3084

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 4 commits into from
May 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions packages/firestore/test/unit/specs/recovery_spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,36 @@ describeSpec('Persistence Recovery', ['no-ios', 'no-android'], () => {
}
);

specTest(
'Clients fail to lookup mutations (with recovery)',
['multi-client'],
() => {
// Multi-Tab uses a Local Storage notification to inform all tabs about
// changes to a mutation tab. To act upon these changes, the tabs read
// the mutated document from IndexedDB. This test verifies that mutations
// are applied even if the lookup fails temporarily.
return (
client(0)
.expectPrimaryState(true)
// All tabs fail to act upon the Local Storage notifications
.failDatabaseTransactions('Lookup mutation documents')
.client(1)
.expectPrimaryState(false)
.userSets('collection/a', { v: 1 })
.failDatabaseTransactions('Lookup mutation documents')
// All tabs recover and the notifications are processed
.client(0)
.recoverDatabase()
.runTimer(TimerId.AsyncQueueRetry)
.writeAcks('collection/a', 1, { expectUserCallback: false })
.client(1)
.recoverDatabase()
.runTimer(TimerId.AsyncQueueRetry)
.expectUserCallbacks({ acknowledged: ['collection/a'] })
);
}
);

specTest(
'Query raises events in secondary client (with recovery)',
['multi-client'],
Expand Down Expand Up @@ -114,6 +144,55 @@ describeSpec('Persistence Recovery', ['no-ios', 'no-android'], () => {
}
);

specTest(
'Ignores intermittent lease refresh failures (with recovery)',
['multi-client'],
() => {
// This test verifies that an IndexedDB failure during a lease refresh
// does not impact client functionality. Lease refresh failures are
// ignored, as the lease is also verified each time an operation is
// run.
return (
client(0)
.expectPrimaryState(true)
.client(1)
.expectPrimaryState(false)
// Run the initial sequence: The primary client fails its lease refresh
// before the secondary client.
.client(0)
.failDatabaseTransactions('updateClientMetadataAndTryBecomePrimary')
.runTimer(TimerId.ClientMetadataRefresh)
.client(1)
.failDatabaseTransactions('updateClientMetadataAndTryBecomePrimary')
.runTimer(TimerId.ClientMetadataRefresh)
.client(0)
.recoverDatabase()
.runTimer(TimerId.ClientMetadataRefresh)
.expectPrimaryState(true)
.client(1)
.recoverDatabase()
.runTimer(TimerId.ClientMetadataRefresh)
.expectPrimaryState(false)
// Run the opposite sequence: The secondary client fails its lease
// refresh before the primary client.
.client(1)
.failDatabaseTransactions('updateClientMetadataAndTryBecomePrimary')
.runTimer(TimerId.ClientMetadataRefresh)
.client(0)
.failDatabaseTransactions('updateClientMetadataAndTryBecomePrimary')
.runTimer(TimerId.ClientMetadataRefresh)
.client(1)
.recoverDatabase()
.runTimer(TimerId.ClientMetadataRefresh)
.expectPrimaryState(false)
.client(0)
.recoverDatabase()
.runTimer(TimerId.ClientMetadataRefresh)
.expectPrimaryState(true)
);
}
);

specTest('Recovers when write cannot be persisted', [], () => {
return (
spec()
Expand Down