@@ -449,6 +449,74 @@ describe('parsers', function () {
449
449
parser . execute ( new Buffer ( ':' + number + '\r\n' ) )
450
450
assert . strictEqual ( replyCount , 2 )
451
451
} )
452
+
453
+ it ( 'handle big data' , function ( ) {
454
+ if ( Parser . name === 'HiredisReplyParser' ) {
455
+ return this . skip ( )
456
+ }
457
+ var lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, ' +
458
+ 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' +
459
+ 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ' +
460
+ 'ut aliquip ex ea commodo consequat. Duis aute irure dolor in' // 256 chars
461
+ var bigStringArray = ( new Array ( Math . pow ( 2 , 16 ) / lorem . length ) . join ( lorem + ' ' ) ) . split ( ' ' ) // Math.pow(2, 16) chars long
462
+ var startBigBuffer = new Buffer ( '$' + ( 4 * 1024 * 1024 ) + '\r\n' )
463
+ var chunks = new Array ( 64 )
464
+ for ( var i = 0 ; i < 64 ; i ++ ) {
465
+ chunks [ i ] = new Buffer ( bigStringArray . join ( ' ' ) + '.' ) // Math.pow(2, 16) chars long
466
+ }
467
+ var replyCount = 0
468
+ function checkReply ( reply ) {
469
+ assert . strictEqual ( reply . length , 4 * 1024 * 1024 )
470
+ replyCount ++
471
+ }
472
+ var parser = new Parser ( {
473
+ returnReply : checkReply ,
474
+ returnError : returnError ,
475
+ returnFatalError : returnFatalError
476
+ } )
477
+ parser . execute ( startBigBuffer )
478
+ for ( i = 0 ; i < 64 ; i ++ ) {
479
+ assert . strictEqual ( parser . bufferCache . length , i + 1 )
480
+ parser . execute ( chunks [ i ] )
481
+ }
482
+ assert . strictEqual ( replyCount , 0 )
483
+ parser . execute ( new Buffer ( '\r\n' ) )
484
+ assert . strictEqual ( replyCount , 1 )
485
+ } )
486
+
487
+ it ( 'handle big data 2' , function ( ) {
488
+ if ( Parser . name === 'HiredisReplyParser' ) {
489
+ return this . skip ( )
490
+ }
491
+ var lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, ' +
492
+ 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' +
493
+ 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ' +
494
+ 'ut aliquip ex ea commodo consequat. Duis aute irure dolor in' // 256 chars
495
+ var bigStringArray = ( new Array ( Math . pow ( 2 , 16 ) / lorem . length ) . join ( lorem + ' ' ) ) . split ( ' ' ) // Math.pow(2, 16) chars long
496
+ var startBigBuffer = new Buffer ( '\r\n$' + ( 4 * 1024 * 1024 ) + '\r\n' )
497
+ var chunks = new Array ( 64 )
498
+ for ( var i = 0 ; i < 64 ; i ++ ) {
499
+ chunks [ i ] = new Buffer ( bigStringArray . join ( ' ' ) + '.' ) // Math.pow(2, 16) chars long
500
+ }
501
+ var replyCount = 0
502
+ function checkReply ( reply ) {
503
+ replyCount ++
504
+ }
505
+ var parser = new Parser ( {
506
+ returnReply : checkReply ,
507
+ returnError : returnError ,
508
+ returnFatalError : returnFatalError
509
+ } )
510
+ parser . execute ( new Buffer ( '+test' ) )
511
+ parser . execute ( startBigBuffer )
512
+ for ( i = 0 ; i < 64 ; i ++ ) {
513
+ assert . strictEqual ( parser . bufferCache . length , i + 1 )
514
+ parser . execute ( chunks [ i ] )
515
+ }
516
+ assert . strictEqual ( replyCount , 1 )
517
+ parser . execute ( new Buffer ( '\r\n' ) )
518
+ assert . strictEqual ( replyCount , 2 )
519
+ } )
452
520
} )
453
521
} )
454
522
} )
0 commit comments