@@ -4,12 +4,19 @@ const SubStreamInterface =
44 require ( '../../../../lib/s3middleware/azureHelpers/SubStreamInterface' ) ;
55
66describe ( 's3middleware SubStreamInterface.stopStreaming()' , ( ) => {
7- const emittedFinished = {
8- sourceStream : false ,
9- currentStream : false ,
7+ const eventsEmitted = {
8+ sourceStreamUnpiped : false ,
9+ currentStreamStopStreamingToAzure : false ,
10+ currentStreamEnded : false ,
11+ } ;
12+ const expectedSequence = {
13+ sourceStreamUnpiped : 0 ,
14+ currentStreamStopStreamingToAzure : 1 ,
15+ currentStreamEnded : 2 ,
1016 } ;
1117 const data = Buffer . alloc ( 100 ) ;
1218 let dataMarker = 0 ;
19+ let eventSequence = 0 ;
1320 const mockRequest = new stream . Readable ( {
1421 read : ( ) => {
1522 if ( dataMarker >= data . length ) {
@@ -22,18 +29,21 @@ describe('s3middleware SubStreamInterface.stopStreaming()', () => {
2229 } ) ;
2330 const sourceStream = new stream . PassThrough ( ) ;
2431 const subStreamInterface = new SubStreamInterface ( sourceStream ) ;
25- sourceStream . on ( 'finish' , ( ) => {
26- emittedFinished . sourceStream = true ;
32+ sourceStream . on ( 'unpipe' , ( ) => {
33+ eventsEmitted . sourceStreamUnpiped = eventSequence ++ ;
34+ } ) ;
35+ subStreamInterface . _currentStream . on ( 'stopStreamingToAzure' , ( ) => {
36+ eventsEmitted . currentStreamStopStreamingToAzure = eventSequence ++ ;
2737 } ) ;
2838 subStreamInterface . _currentStream . on ( 'finish' , ( ) => {
29- emittedFinished . currentStream = true ;
39+ eventsEmitted . currentStreamEnded = eventSequence ++ ;
3040 } ) ;
31- it ( 'should stop streaming data and end all streams ' , done => {
41+ it ( 'should stop streaming data and end current stream ' , done => {
3242 sourceStream . on ( 'data' , chunk => {
3343 const currentLength = subStreamInterface . getLengthCounter ( ) ;
3444 if ( currentLength === 10 ) {
35- Object . keys ( emittedFinished ) . forEach ( key => {
36- assert . strictEqual ( emittedFinished [ key ] , false ) ;
45+ Object . keys ( eventsEmitted ) . forEach ( key => {
46+ assert . strictEqual ( eventsEmitted [ key ] , false ) ;
3747 } ) ;
3848 assert . strictEqual ( mockRequest . _readableState . pipesCount , 1 ) ;
3949 return subStreamInterface . stopStreaming ( mockRequest ) ;
@@ -42,8 +52,8 @@ describe('s3middleware SubStreamInterface.stopStreaming()', () => {
4252 } ) ;
4353 mockRequest . pipe ( sourceStream ) ;
4454 setTimeout ( ( ) => {
45- Object . keys ( emittedFinished ) . forEach ( key => {
46- assert . strictEqual ( emittedFinished [ key ] , true ) ;
55+ Object . keys ( eventsEmitted ) . forEach ( key => {
56+ assert . strictEqual ( eventsEmitted [ key ] , expectedSequence [ key ] ) ;
4757 } ) ;
4858 assert . strictEqual ( subStreamInterface . getLengthCounter ( ) , 10 ) ;
4959 assert . strictEqual ( mockRequest . _readableState . pipesCount , 0 ) ;
0 commit comments