@@ -519,16 +519,28 @@ describe('client submit', function() {
519519 if ( err ) return done ( err ) ;
520520 var docCallback ;
521521 var doc2Callback ;
522+ // The submit retry happens just after an op is committed. This hook into the middleware
523+ // catches both ops just before they're about to be committed. This ensures that both ops
524+ // are certainly working on the same snapshot (ie one op hasn't been committed before the
525+ // other fetches the snapshot to apply to). By storing the callbacks, we can then
526+ // manually trigger the callbacks, first calling doc, and when we know that's been committed,
527+ // we then commit doc2.
522528 backend . use ( 'commit' , function ( request , callback ) {
523529 if ( request . op . op [ 0 ] . na === 2 ) docCallback = callback ;
524530 if ( request . op . op [ 0 ] . na === 7 ) doc2Callback = callback ;
525531
532+ // Wait until both ops have been applied to the same snapshot and are about to be committed
526533 if ( docCallback && doc2Callback ) {
534+ // Trigger the first op's commit and then the second one later, which will cause the
535+ // second op to retry
527536 docCallback ( ) ;
528537 }
529538 } ) ;
530539 doc . submitOp ( { p : [ 'age' ] , na : 2 } , function ( error ) {
531540 if ( error ) return done ( error ) ;
541+ // When we know the first op has been committed, we try to commit the second op, which will
542+ // fail because it's working on an out-of-date snapshot. It will retry, but exceed the
543+ // maxSubmitRetries limit of 0
532544 doc2Callback ( ) ;
533545 } ) ;
534546 doc2 . submitOp ( { p : [ 'age' ] , na : 7 } , function ( error ) {
0 commit comments