-
Notifications
You must be signed in to change notification settings - Fork 934
Retry WebStorage operations #2879
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
Changes from all commits
d3c8e55
4d7eb94
b79b9ca
d2fa82a
7b538dc
00af1f3
aba251d
0f07ebe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* @license | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { describeSpec, specTest } from './describe_spec'; | ||
import { client } from './spec_builder'; | ||
import { TimerId } from '../../../src/util/async_queue'; | ||
import { Query } from '../../../src/core/query'; | ||
import { path } from '../../util/helpers'; | ||
|
||
describeSpec( | ||
'Persistence Recovery', | ||
['durable-persistence', 'no-ios', 'no-android'], | ||
() => { | ||
specTest( | ||
'Write is acknowledged by primary client (with recovery)', | ||
['multi-client'], | ||
() => { | ||
return ( | ||
client(0) | ||
.expectPrimaryState(true) | ||
.client(1) | ||
.expectPrimaryState(false) | ||
.userSets('collection/a', { v: 1 }) | ||
.failDatabase() | ||
.client(0) | ||
.writeAcks('collection/a', 1, { expectUserCallback: false }) | ||
.client(1) | ||
// Client 1 has received the WebStorage notification that the write | ||
// has been acknowledged, but failed to process the change. Hence, | ||
// we did not get a user callback. We schedule the first retry and | ||
// make sure that it also does not get processed until | ||
// `recoverDatabase` is called. | ||
.runTimer(TimerId.AsyncQueueRetry) | ||
.recoverDatabase() | ||
.runTimer(TimerId.AsyncQueueRetry) | ||
.expectUserCallbacks({ | ||
acknowledged: ['collection/a'] | ||
}) | ||
); | ||
} | ||
); | ||
|
||
specTest( | ||
'Query raises events in secondary client (with recovery)', | ||
['multi-client'], | ||
() => { | ||
const query = Query.atPath(path('collection')); | ||
|
||
return client(0) | ||
.expectPrimaryState(true) | ||
.client(1) | ||
.expectPrimaryState(false) | ||
.userListens(query) | ||
.failDatabase() | ||
.client(0) | ||
.expectListen(query) | ||
.watchAcksFull(query, 1000) | ||
.client(1) | ||
.recoverDatabase() | ||
.runTimer(TimerId.AsyncQueueRetry) | ||
.expectEvents(query, {}); | ||
} | ||
); | ||
} | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,6 +418,24 @@ export class SpecBuilder { | |
return this; | ||
} | ||
|
||
/** Fails all database operations until `recoverDatabase()` is called. */ | ||
failDatabase(): this { | ||
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. Could you add comments here about how this works? I suspect this works by modifying all steps going forward until recoverDatabase is called, but the code here suggests this merely modifies the current step only. 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. This ends up calling |
||
this.nextStep(); | ||
this.currentStep = { | ||
failDatabase: true | ||
}; | ||
return this; | ||
} | ||
|
||
/** Stops failing database operations. */ | ||
recoverDatabase(): this { | ||
this.nextStep(); | ||
this.currentStep = { | ||
failDatabase: false | ||
}; | ||
return this; | ||
} | ||
|
||
expectIsShutdown(): this { | ||
this.assertStep('Active target expectation requires previous step'); | ||
const currentStep = this.currentStep!; | ||
|
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: the inconsistency between "retry" at the beginning vs end of the enumeration entry is a little glaring.
RetryAsyncQueue
sounds a little weird. Maybe renameRetryTransaction
toTransactionRetry
to match?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.
Renamed
RetryTransaction
.