15
15
*/
16
16
'use strict' ;
17
17
const assert = require ( 'assert' ) ;
18
+ const events = require ( 'events' ) ;
18
19
19
20
const Encoder = require ( '../../lib/encoder' ) ;
20
21
const streams = require ( '../../lib/streams' ) ;
@@ -948,6 +949,28 @@ describe('Parser', function () {
948
949
} ) ;
949
950
} ) ;
950
951
describe ( 'with multiple chunk lengths piped' , function ( ) {
952
+
953
+ const expected = [
954
+ { columnLength : 3 , rowLength : 10 } ,
955
+ { columnLength : 5 , rowLength : 5 } ,
956
+ { columnLength : 6 , rowLength : 15 } ,
957
+ { columnLength : 6 , rowLength : 15 } ,
958
+ { columnLength : 1 , rowLength : 20 }
959
+ ] ;
960
+
961
+ class TestEmitter extends events . EventEmitter { }
962
+ const emitter = new TestEmitter ( ) ;
963
+ const doneParsing = new Promise ( ( resolve ) => {
964
+
965
+ let cnt = 0 ;
966
+ emitter . on ( 'parseDone' , ( ) => {
967
+ cnt += 1 ;
968
+ if ( cnt === expected . length ) {
969
+ resolve ( ) ;
970
+ }
971
+ } ) ;
972
+ } ) ;
973
+
951
974
const protocol = new streams . Protocol ( { objectMode : true } ) ;
952
975
const parser = newInstance ( ) ;
953
976
protocol . pipe ( parser ) ;
@@ -961,6 +984,7 @@ describe('Parser', function () {
961
984
}
962
985
byRowCompleted = item . byRowCompleted ;
963
986
if ( byRowCompleted ) {
987
+ emitter . emit ( 'parseDone' ) ;
964
988
continue ;
965
989
}
966
990
assert . strictEqual ( item . header . opcode , types . opcodes . result ) ;
@@ -969,13 +993,6 @@ describe('Parser', function () {
969
993
result [ item . header . streamId ] . push ( item . row ) ;
970
994
}
971
995
} ) ;
972
- const expected = [
973
- { columnLength : 3 , rowLength : 10 } ,
974
- { columnLength : 5 , rowLength : 5 } ,
975
- { columnLength : 6 , rowLength : 15 } ,
976
- { columnLength : 6 , rowLength : 15 } ,
977
- { columnLength : 1 , rowLength : 20 }
978
- ] ;
979
996
[ 1 , 2 , 7 , 11 ] . forEach ( function ( chunkLength ) {
980
997
it ( 'should emit rows chunked with chunk length of ' + chunkLength , function ( done ) {
981
998
result = { } ;
@@ -992,15 +1009,18 @@ describe('Parser', function () {
992
1009
}
993
1010
protocol . _transform ( buffer . slice ( j , end ) , null , helper . throwop ) ;
994
1011
}
995
- process . nextTick ( ( ) => {
996
- assert . ok ( byRowCompleted ) ;
997
- //assert result
998
- expected . forEach ( function ( expectedItem , index ) {
999
- assert . ok ( result [ index ] , 'Result not found for index ' + index ) ;
1000
- assert . strictEqual ( result [ index ] . length , expectedItem . rowLength ) ;
1001
- assert . strictEqual ( result [ index ] [ 0 ] . keys ( ) . length , expectedItem . columnLength ) ;
1012
+ doneParsing . then ( ( ) => {
1013
+
1014
+ process . nextTick ( ( ) => {
1015
+ assert . ok ( byRowCompleted ) ;
1016
+ //assert result
1017
+ expected . forEach ( function ( expectedItem , index ) {
1018
+ assert . ok ( result [ index ] , 'Result not found for index ' + index ) ;
1019
+ assert . strictEqual ( result [ index ] . length , expectedItem . rowLength ) ;
1020
+ assert . strictEqual ( result [ index ] [ 0 ] . keys ( ) . length , expectedItem . columnLength ) ;
1021
+ } ) ;
1022
+ done ( ) ;
1002
1023
} ) ;
1003
- done ( ) ;
1004
1024
} ) ;
1005
1025
} ) ;
1006
1026
} ) ;
0 commit comments