File tree Expand file tree Collapse file tree 3 files changed +9
-5
lines changed Expand file tree Collapse file tree 3 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -25,14 +25,14 @@ import { isNullOrUndefined } from '../util/types';
2525
2626import { Transaction } from './transaction' ;
2727
28- const RETRY_COUNT = 5 ;
28+ export const DEFAULT_MAX_ATTEMPTS_COUNT = 5 ;
2929
3030/**
3131 * TransactionRunner encapsulates the logic needed to run and retry transactions
3232 * with backoff.
3333 */
3434export class TransactionRunner < T > {
35- private retries = RETRY_COUNT ;
35+ private attemptsRemaining = DEFAULT_MAX_ATTEMPTS_COUNT ;
3636 private backoff : ExponentialBackoff ;
3737
3838 constructor (
@@ -49,6 +49,7 @@ export class TransactionRunner<T> {
4949
5050 /** Runs the transaction and sets the result on deferred. */
5151 run ( ) : void {
52+ this . attemptsRemaining -= 1 ;
5253 this . runWithBackOff ( ) ;
5354 }
5455
@@ -99,8 +100,8 @@ export class TransactionRunner<T> {
99100 }
100101
101102 private handleTransactionError ( error : Error ) : void {
102- if ( this . retries > 0 && this . isRetryableTransactionError ( error ) ) {
103- this . retries -= 1 ;
103+ if ( this . attemptsRemaining > 0 && this . isRetryableTransactionError ( error ) ) {
104+ this . attemptsRemaining -= 1 ;
104105 this . asyncQueue . enqueueAndForget ( ( ) => {
105106 this . runWithBackOff ( ) ;
106107 return Promise . resolve ( ) ;
Original file line number Diff line number Diff line change 1818import * as firestore from '@firebase/firestore-types' ;
1919import { expect } from 'chai' ;
2020
21+ import { DEFAULT_MAX_ATTEMPTS_COUNT } from '../../../src/core/transaction_runner' ;
2122import { TimerId } from '../../../src/util/async_queue' ;
2223import { Deferred } from '../../util/promise' ;
2324import * as integrationHelpers from '../util/helpers' ;
@@ -183,6 +184,7 @@ apiDescribe(
183184 . then ( ( ) => doc . get ( ) )
184185 . then ( snapshot => {
185186 expect ( snapshot . data ( ) ! [ 'count' ] ) . to . equal ( 1234 + counter ) ;
187+ expect ( counter ) . to . equal ( DEFAULT_MAX_ATTEMPTS_COUNT ) ;
186188 } ) ;
187189 } ) ;
188190 } ) ;
Original file line number Diff line number Diff line change @@ -49,7 +49,8 @@ export function getDefaultDatabaseInfo(): DatabaseInfo {
4949 DEFAULT_SETTINGS . host ! ,
5050 ! ! DEFAULT_SETTINGS . ssl ,
5151 ! ! DEFAULT_SETTINGS . experimentalForceLongPolling ,
52- ! ! DEFAULT_SETTINGS . experimentalAutoDetectLongPolling
52+ ! ! DEFAULT_SETTINGS . experimentalAutoDetectLongPolling ,
53+ /*use FetchStreams= */ false
5354 ) ;
5455}
5556
You can’t perform that action at this time.
0 commit comments