@@ -473,48 +473,44 @@ types.register(presenceType.type3);
473
473
] , allDone ) ;
474
474
} ) ;
475
475
476
- it ( 'removes cached ops' , function ( allDone ) {
477
- var op = { index : 1 , value : 'b' } ;
478
- this . doc . cachedOpsTimeout = 0 ;
476
+ it ( 'expires cached ops' , function ( allDone ) {
477
+ var op1 = { index : 1 , value : 'b' } ;
478
+ var op2 = { index : 2 , value : 'b' } ;
479
+ var op3 = { index : 3 , value : 'b' } ;
480
+ this . doc . cachedOpsTimeout = 60 ;
479
481
async . series ( [
482
+ // Cache 2 ops.
480
483
this . doc . create . bind ( this . doc , [ 'a' ] , typeName ) ,
481
- this . doc . submitOp . bind ( this . doc , op ) ,
482
- this . doc . del . bind ( this . doc ) ,
484
+ this . doc . submitOp . bind ( this . doc , op1 ) ,
483
485
function ( done ) {
484
- expect ( this . doc . cachedOps . length ) . to . equal ( 3 ) ;
486
+ expect ( this . doc . cachedOps . length ) . to . equal ( 2 ) ;
485
487
expect ( this . doc . cachedOps [ 0 ] . create ) . to . equal ( true ) ;
486
- expect ( this . doc . cachedOps [ 1 ] . op ) . to . equal ( op ) ;
487
- expect ( this . doc . cachedOps [ 2 ] . del ) . to . equal ( true ) ;
488
+ expect ( this . doc . cachedOps [ 1 ] . op ) . to . equal ( op1 ) ;
488
489
done ( ) ;
489
490
} . bind ( this ) ,
490
- setTimeout ,
491
- function ( done ) {
492
- expect ( this . doc . cachedOps . length ) . to . equal ( 0 ) ;
493
- done ( ) ;
494
- } . bind ( this )
495
- ] , allDone ) ;
496
- } ) ;
497
491
498
- it ( 'removes correct cached ops' , function ( allDone ) {
499
- var op = { index : 1 , value : 'b' } ;
500
- this . doc . cachedOpsTimeout = 0 ;
501
- async . series ( [
502
- this . doc . create . bind ( this . doc , [ 'a' ] , typeName ) ,
503
- this . doc . submitOp . bind ( this . doc , op ) ,
504
- this . doc . del . bind ( this . doc ) ,
492
+ // Cache another op before the first 2 expire.
493
+ function ( callback ) {
494
+ setTimeout ( callback , 30 ) ;
495
+ } ,
496
+ this . doc . submitOp . bind ( this . doc , op2 ) ,
505
497
function ( done ) {
506
498
expect ( this . doc . cachedOps . length ) . to . equal ( 3 ) ;
507
499
expect ( this . doc . cachedOps [ 0 ] . create ) . to . equal ( true ) ;
508
- expect ( this . doc . cachedOps [ 1 ] . op ) . to . equal ( op ) ;
509
- expect ( this . doc . cachedOps [ 2 ] . del ) . to . equal ( true ) ;
510
- this . doc . cachedOps . shift ( ) ;
511
- this . doc . cachedOps . push ( { op : true } ) ;
500
+ expect ( this . doc . cachedOps [ 1 ] . op ) . to . equal ( op1 ) ;
501
+ expect ( this . doc . cachedOps [ 2 ] . op ) . to . equal ( op2 ) ;
512
502
done ( ) ;
513
503
} . bind ( this ) ,
514
- setTimeout ,
504
+
505
+ // Cache another op after the first 2 expire.
506
+ function ( callback ) {
507
+ setTimeout ( callback , 31 ) ;
508
+ } ,
509
+ this . doc . submitOp . bind ( this . doc , op3 ) ,
515
510
function ( done ) {
516
- expect ( this . doc . cachedOps . length ) . to . equal ( 1 ) ;
517
- expect ( this . doc . cachedOps [ 0 ] . op ) . to . equal ( true ) ;
511
+ expect ( this . doc . cachedOps . length ) . to . equal ( 2 ) ;
512
+ expect ( this . doc . cachedOps [ 0 ] . op ) . to . equal ( op2 ) ;
513
+ expect ( this . doc . cachedOps [ 1 ] . op ) . to . equal ( op3 ) ;
518
514
done ( ) ;
519
515
} . bind ( this )
520
516
] , allDone ) ;
0 commit comments