@@ -95,17 +95,22 @@ describe('Parser', function () {
95
95
header : getFrameHeader ( 4 , types . opcodes . result , 2 , true ) ,
96
96
chunk : body
97
97
} , null , doneIfError ( done ) ) ;
98
- assert . strictEqual ( responseCounter , 1 ) ;
99
- parser . setOptions ( 88 , { byRow : true } ) ;
100
- for ( let i = 0 ; i < body . length ; i ++ ) {
101
- parser . _transform ( {
102
- header : getFrameHeader ( 4 , types . opcodes . result , 2 , true , 88 ) ,
103
- chunk : body . slice ( i , i + 1 ) ,
104
- offset : 0
105
- } , null , doneIfError ( done ) ) ;
106
- }
107
- assert . strictEqual ( responseCounter , 2 ) ;
108
- done ( ) ;
98
+
99
+ process . nextTick ( ( ) => {
100
+ assert . strictEqual ( responseCounter , 1 ) ;
101
+ parser . setOptions ( 88 , { byRow : true } ) ;
102
+ for ( let i = 0 ; i < body . length ; i ++ ) {
103
+ parser . _transform ( {
104
+ header : getFrameHeader ( 4 , types . opcodes . result , 2 , true , 88 ) ,
105
+ chunk : body . slice ( i , i + 1 ) ,
106
+ offset : 0
107
+ } , null , doneIfError ( done ) ) ;
108
+ }
109
+ process . nextTick ( ( ) => {
110
+ assert . strictEqual ( responseCounter , 2 ) ;
111
+ done ( ) ;
112
+ } ) ;
113
+ } ) ;
109
114
} ) ;
110
115
it ( 'should read a RESULT result with trace id chunked' , function ( done ) {
111
116
const parser = newInstance ( ) ;
@@ -125,17 +130,21 @@ describe('Parser', function () {
125
130
chunk : body ,
126
131
offset : 0
127
132
} , null , doneIfError ( done ) ) ;
128
- assert . strictEqual ( responseCounter , 1 ) ;
129
- parser . setOptions ( 88 , { byRow : true } ) ;
130
- for ( let i = 0 ; i < body . length ; i ++ ) {
131
- parser . _transform ( {
132
- header : getFrameHeader ( 4 , types . opcodes . result , 2 , true , 88 ) ,
133
- chunk : body . slice ( i , i + 1 ) ,
134
- offset : 0
135
- } , null , doneIfError ( done ) ) ;
136
- }
137
- assert . strictEqual ( responseCounter , 2 ) ;
138
- done ( ) ;
133
+ process . nextTick ( ( ) => {
134
+ assert . strictEqual ( responseCounter , 1 ) ;
135
+ parser . setOptions ( 88 , { byRow : true } ) ;
136
+ for ( let i = 0 ; i < body . length ; i ++ ) {
137
+ parser . _transform ( {
138
+ header : getFrameHeader ( 4 , types . opcodes . result , 2 , true , 88 ) ,
139
+ chunk : body . slice ( i , i + 1 ) ,
140
+ offset : 0
141
+ } , null , doneIfError ( done ) ) ;
142
+ }
143
+ process . nextTick ( ( ) => {
144
+ assert . strictEqual ( responseCounter , 2 ) ;
145
+ done ( ) ;
146
+ } ) ;
147
+ } ) ;
139
148
} ) ;
140
149
it ( 'should read a VOID result with warnings and custom payload' , function ( done ) {
141
150
const parser = newInstance ( ) ;
@@ -743,11 +752,16 @@ describe('Parser', function () {
743
752
const rowLength = 2 ;
744
753
let rowCounter = 0 ;
745
754
parser . on ( 'readable' , function ( ) {
746
- const item = parser . read ( ) ;
747
- assert . strictEqual ( item . header . opcode , types . opcodes . result ) ;
748
- assert . ok ( item . row ) ;
749
- if ( ( ++ rowCounter ) === rowLength ) {
750
- done ( ) ;
755
+ let item ;
756
+ while ( ( item = parser . read ( ) ) ) {
757
+ if ( ! item . row && item . frameEnded ) {
758
+ continue ;
759
+ }
760
+ assert . strictEqual ( item . header . opcode , types . opcodes . result ) ;
761
+ assert . ok ( item . row ) ;
762
+ if ( ( ++ rowCounter ) === rowLength ) {
763
+ done ( ) ;
764
+ }
751
765
}
752
766
} ) ;
753
767
parser . setOptions ( 33 , { byRow : true } ) ;
@@ -773,7 +787,7 @@ describe('Parser', function () {
773
787
}
774
788
} ) ;
775
789
[ 1 , 3 , 5 , 13 ] . forEach ( function ( chunkLength ) {
776
- it ( 'should emit rows chunked with chunk length of ' + chunkLength , function ( ) {
790
+ it ( 'should emit rows chunked with chunk length of ' + chunkLength , function ( done ) {
777
791
result = { } ;
778
792
const expected = [
779
793
{ columnLength : 3 , rowLength : 10 } ,
@@ -814,10 +828,13 @@ describe('Parser', function () {
814
828
for ( let i = 0 ; i < items . length ; i ++ ) {
815
829
transformChunkedItem ( i ) ;
816
830
}
817
- //assert result
818
- expected . forEach ( function ( expectedItem , index ) {
819
- assert . ok ( result [ index ] , 'Result not found for index ' + index ) ;
820
- assert . strictEqual ( result [ index ] . length , expectedItem . rowLength ) ;
831
+ process . nextTick ( ( ) => {
832
+ //assert result
833
+ expected . forEach ( function ( expectedItem , index ) {
834
+ assert . ok ( result [ index ] , 'Result not found for index ' + index ) ;
835
+ assert . strictEqual ( result [ index ] . length , expectedItem . rowLength ) ;
836
+ } ) ;
837
+ done ( ) ;
821
838
} ) ;
822
839
} ) ;
823
840
} ) ;
@@ -847,7 +864,7 @@ describe('Parser', function () {
847
864
{ columnLength : 1 , rowLength : 20 }
848
865
] ;
849
866
[ 1 , 2 , 7 , 11 ] . forEach ( function ( chunkLength ) {
850
- it ( 'should emit rows chunked with chunk length of ' + chunkLength , function ( ) {
867
+ it ( 'should emit rows chunked with chunk length of ' + chunkLength , function ( done ) {
851
868
result = { } ;
852
869
const buffer = Buffer . concat ( expected . map ( function ( expectedItem , index ) {
853
870
parser . setOptions ( index , { byRow : true } ) ;
@@ -862,11 +879,14 @@ describe('Parser', function () {
862
879
}
863
880
protocol . _transform ( buffer . slice ( j , end ) , null , helper . throwop ) ;
864
881
}
865
- //assert result
866
- expected . forEach ( function ( expectedItem , index ) {
867
- assert . ok ( result [ index ] , 'Result not found for index ' + index ) ;
868
- assert . strictEqual ( result [ index ] . length , expectedItem . rowLength ) ;
869
- assert . strictEqual ( result [ index ] [ 0 ] . keys ( ) . length , expectedItem . columnLength ) ;
882
+ process . nextTick ( ( ) => {
883
+ //assert result
884
+ expected . forEach ( function ( expectedItem , index ) {
885
+ assert . ok ( result [ index ] , 'Result not found for index ' + index ) ;
886
+ assert . strictEqual ( result [ index ] . length , expectedItem . rowLength ) ;
887
+ assert . strictEqual ( result [ index ] [ 0 ] . keys ( ) . length , expectedItem . columnLength ) ;
888
+ } ) ;
889
+ done ( ) ;
870
890
} ) ;
871
891
} ) ;
872
892
} ) ;
@@ -1021,10 +1041,14 @@ describe('Parser', function () {
1021
1041
parser . _transform ( getBodyChunks ( 3 , rowLength , 0 , 10 ) , null , doneIfError ( done ) ) ;
1022
1042
parser . _transform ( getBodyChunks ( 3 , rowLength , 10 , 32 ) , null , doneIfError ( done ) ) ;
1023
1043
parser . _transform ( getBodyChunks ( 3 , rowLength , 32 , 55 ) , null , doneIfError ( done ) ) ;
1024
- assert . strictEqual ( rowCounter , 1 ) ;
1025
- parser . _transform ( getBodyChunks ( 3 , rowLength , 55 , null ) , null , doneIfError ( done ) ) ;
1026
- assert . strictEqual ( rowCounter , 2 ) ;
1027
- done ( ) ;
1044
+ process . nextTick ( ( ) => {
1045
+ assert . strictEqual ( rowCounter , 1 ) ;
1046
+ parser . _transform ( getBodyChunks ( 3 , rowLength , 55 , null ) , null , doneIfError ( done ) ) ;
1047
+ process . nextTick ( ( ) => {
1048
+ assert . strictEqual ( rowCounter , 2 ) ;
1049
+ done ( ) ;
1050
+ } ) ;
1051
+ } ) ;
1028
1052
} ) ;
1029
1053
} ) ;
1030
1054
} ) ;
0 commit comments