@@ -5,6 +5,8 @@ import { type CommandFailedEvent, type MongoClient } from '../../mongodb';
55import { configureFailPoint } from '../../tools/utils' ;
66import { filterForCommands } from '../shared' ;
77
8+ const COMMIT_FAIL_TIMES = 35 ;
9+
810describe ( 'Retry Backoff is Enforced' , function ( ) {
911 // Drivers should test that retries within `withTransaction` do not occur immediately. Optionally, set BACKOFF_INITIAL to a
1012 // higher value to decrease flakiness of this test. Configure a fail point that forces 30 retries. Check that the total
@@ -24,12 +26,11 @@ describe('Retry Backoff is Enforced', function () {
2426 await configureFailPoint ( this . configuration , {
2527 configureFailPoint : 'failCommand' ,
2628 mode : {
27- times : 30
29+ times : COMMIT_FAIL_TIMES
2830 } ,
2931 data : {
3032 failCommands : [ 'commitTransaction' ] ,
31- errorCode : 24 ,
32- errorLabels : [ 'UnknownTransactionCommitResult' ]
33+ errorCode : 24
3334 }
3435 } ) ;
3536 } ) ;
@@ -39,20 +40,29 @@ describe('Retry Backoff is Enforced', function () {
3940 } ) ;
4041
4142 for ( let i = 0 ; i < 250 ; ++ i ) {
42- test . only ( 'works' + i , async function ( ) {
43- const start = performance . now ( ) ;
43+ test . only (
44+ 'works' + i ,
45+ {
46+ requires : {
47+ mongodb : '>=4.4' , // failCommand
48+ topology : '!single' // transactions can't run on standalone servers
49+ }
50+ } ,
51+ async function ( ) {
52+ const start = performance . now ( ) ;
4453
45- await client . withSession ( async s => {
46- await s . withTransaction ( async s => {
47- await client . db ( 'foo' ) . collection ( 'bar' ) . insertOne ( { name : 'bailey' } , { session : s } ) ;
54+ await client . withSession ( async s => {
55+ await s . withTransaction ( async s => {
56+ await client . db ( 'foo' ) . collection ( 'bar' ) . insertOne ( { name : 'bailey' } , { session : s } ) ;
57+ } ) ;
4858 } ) ;
49- } ) ;
5059
51- const end = performance . now ( ) ;
60+ const end = performance . now ( ) ;
5261
53- expect ( failures ) . to . have . lengthOf ( 30 ) ;
62+ expect ( failures ) . to . have . lengthOf ( COMMIT_FAIL_TIMES ) ;
5463
55- expect ( end - start ) . to . be . greaterThan ( 1250 ) ;
56- } ) ;
64+ expect ( end - start ) . to . be . greaterThan ( 1500 ) ;
65+ }
66+ ) ;
5767 }
5868} ) ;
0 commit comments