-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To end streaming in case of error, we were calling an unofficial method of the stream API which was removed and does not exist in the version of node we use. The method is re-added officially in node v.8 but until we upgrade we need to destroy the streams manually, by pushing null for readables and calling stream.end() for writables.
- Loading branch information
1 parent
1270412
commit 71db931
Showing
3 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
tests/unit/s3middleware/azureHelpers/SubStreamingInterface.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const assert = require('assert'); | ||
const stream = require('stream'); | ||
const SubStreamInterface = | ||
require('../../../../lib/s3middleware/azureHelpers/SubStreamInterface'); | ||
|
||
describe('s3middleware SubStreamInterface.stopStreaming()', () => { | ||
const eventsEmitted = { | ||
sourceStreamUnpiped: false, | ||
currentStreamStopStreamingToAzure: false, | ||
currentStreamEnded: false, | ||
}; | ||
const expectedSequence = { | ||
sourceStreamUnpiped: 0, | ||
currentStreamStopStreamingToAzure: 1, | ||
currentStreamEnded: 2, | ||
}; | ||
const data = Buffer.alloc(100); | ||
let dataMarker = 0; | ||
let eventSequence = 0; | ||
const mockRequest = new stream.Readable({ | ||
read: () => { | ||
if (dataMarker >= data.length) { | ||
return mockRequest.push(null); | ||
} | ||
mockRequest.push(data.slice(dataMarker, dataMarker + 1)); | ||
dataMarker += 1; | ||
return undefined; | ||
}, | ||
}); | ||
const sourceStream = new stream.PassThrough(); | ||
const subStreamInterface = new SubStreamInterface(sourceStream); | ||
sourceStream.on('unpipe', () => { | ||
eventsEmitted.sourceStreamUnpiped = eventSequence++; | ||
}); | ||
subStreamInterface._currentStream.on('stopStreamingToAzure', () => { | ||
eventsEmitted.currentStreamStopStreamingToAzure = eventSequence++; | ||
}); | ||
subStreamInterface._currentStream.on('finish', () => { | ||
eventsEmitted.currentStreamEnded = eventSequence++; | ||
}); | ||
it('should stop streaming data and end current stream', done => { | ||
sourceStream.on('data', chunk => { | ||
const currentLength = subStreamInterface.getLengthCounter(); | ||
if (currentLength === 10) { | ||
Object.keys(eventsEmitted).forEach(key => { | ||
assert.strictEqual(eventsEmitted[key], false); | ||
}); | ||
assert.strictEqual(mockRequest._readableState.pipesCount, 1); | ||
return subStreamInterface.stopStreaming(mockRequest); | ||
} | ||
return subStreamInterface.write(chunk); | ||
}); | ||
mockRequest.pipe(sourceStream); | ||
setTimeout(() => { | ||
Object.keys(eventsEmitted).forEach(key => { | ||
assert.strictEqual(eventsEmitted[key], expectedSequence[key]); | ||
}); | ||
assert.strictEqual(subStreamInterface.getLengthCounter(), 10); | ||
assert.strictEqual(mockRequest._readableState.pipesCount, 0); | ||
return done(); | ||
}, 1000); | ||
}); | ||
}); |