File tree 3 files changed +9
-5
lines changed 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';
25
25
26
26
import { Transaction } from './transaction' ;
27
27
28
- const RETRY_COUNT = 5 ;
28
+ export const DEFAULT_MAX_ATTEMPTS_COUNT = 5 ;
29
29
30
30
/**
31
31
* TransactionRunner encapsulates the logic needed to run and retry transactions
32
32
* with backoff.
33
33
*/
34
34
export class TransactionRunner < T > {
35
- private retries = RETRY_COUNT ;
35
+ private attemptsRemaining = DEFAULT_MAX_ATTEMPTS_COUNT ;
36
36
private backoff : ExponentialBackoff ;
37
37
38
38
constructor (
@@ -49,6 +49,7 @@ export class TransactionRunner<T> {
49
49
50
50
/** Runs the transaction and sets the result on deferred. */
51
51
run ( ) : void {
52
+ this . attemptsRemaining -= 1 ;
52
53
this . runWithBackOff ( ) ;
53
54
}
54
55
@@ -99,8 +100,8 @@ export class TransactionRunner<T> {
99
100
}
100
101
101
102
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 ;
104
105
this . asyncQueue . enqueueAndForget ( ( ) => {
105
106
this . runWithBackOff ( ) ;
106
107
return Promise . resolve ( ) ;
Original file line number Diff line number Diff line change 18
18
import * as firestore from '@firebase/firestore-types' ;
19
19
import { expect } from 'chai' ;
20
20
21
+ import { DEFAULT_MAX_ATTEMPTS_COUNT } from '../../../src/core/transaction_runner' ;
21
22
import { TimerId } from '../../../src/util/async_queue' ;
22
23
import { Deferred } from '../../util/promise' ;
23
24
import * as integrationHelpers from '../util/helpers' ;
@@ -183,6 +184,7 @@ apiDescribe(
183
184
. then ( ( ) => doc . get ( ) )
184
185
. then ( snapshot => {
185
186
expect ( snapshot . data ( ) ! [ 'count' ] ) . to . equal ( 1234 + counter ) ;
187
+ expect ( counter ) . to . equal ( DEFAULT_MAX_ATTEMPTS_COUNT ) ;
186
188
} ) ;
187
189
} ) ;
188
190
} ) ;
Original file line number Diff line number Diff line change @@ -49,7 +49,8 @@ export function getDefaultDatabaseInfo(): DatabaseInfo {
49
49
DEFAULT_SETTINGS . host ! ,
50
50
! ! DEFAULT_SETTINGS . ssl ,
51
51
! ! DEFAULT_SETTINGS . experimentalForceLongPolling ,
52
- ! ! DEFAULT_SETTINGS . experimentalAutoDetectLongPolling
52
+ ! ! DEFAULT_SETTINGS . experimentalAutoDetectLongPolling ,
53
+ /*use FetchStreams= */ false
53
54
) ;
54
55
}
55
56
You can’t perform that action at this time.
0 commit comments