@@ -40,55 +40,6 @@ test('protocol carries control payloads', (t) => {
4040 worker . send ( 'exit' , { code : 42 } )
4141} )
4242
43- test ( 'protocol reassembles partial frames' , ( t ) => {
44- t . plan ( 1 )
45-
46- const [ , right ] = pair ( )
47- const worker = protocol . attach ( right )
48-
49- worker . on ( 'data' , ( data ) => {
50- t . alike ( data , Buffer . from ( 'reassembled' ) )
51- } )
52-
53- const payload = Buffer . from ( 'reassembled' )
54- const frame = Buffer . alloc ( 5 + payload . length )
55- frame . writeUInt32LE ( payload . length + 1 , 0 )
56- frame . writeUInt8 ( 0x01 , 4 )
57- payload . copy ( frame , 5 )
58-
59- for ( let i = 0 ; i < frame . length ; i ++ ) {
60- right . push ( Buffer . from ( [ frame [ i ] ] ) )
61- }
62- } )
63-
64- test ( 'protocol coalesces multiple frames in one chunk' , ( t ) => {
65- t . plan ( 2 )
66-
67- const [ , right ] = pair ( )
68- const worker = protocol . attach ( right )
69-
70- const received = [ ]
71-
72- worker . on ( 'data' , ( data ) => {
73- received . push ( data . toString ( ) )
74-
75- if ( received . length === 2 ) {
76- t . is ( received [ 0 ] , 'a' )
77- t . is ( received [ 1 ] , 'b' )
78- }
79- } )
80-
81- function frame ( payload ) {
82- const buf = Buffer . alloc ( 5 + payload . length )
83- buf . writeUInt32LE ( payload . length + 1 , 0 )
84- buf . writeUInt8 ( 0x01 , 4 )
85- payload . copy ( buf , 5 )
86- return buf
87- }
88-
89- right . push ( Buffer . concat ( [ frame ( Buffer . from ( 'a' ) ) , frame ( Buffer . from ( 'b' ) ) ] ) )
90- } )
91-
9243function pair ( ) {
9344 let a , b
9445
0 commit comments