Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: check that abort() exists #879

Merged
merged 1 commit into from
Sep 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,12 @@ File.prototype.createReadStream = function(options) {
})
.pipe(throughStream)
.on('error', function() {
requestStream.abort();
// An error can occur before the request stream has been created (during
// authentication).
if (requestStream.abort) {
requestStream.abort();
}

requestStream.destroy();
});
}
Expand Down
18 changes: 18 additions & 0 deletions test/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,24 @@ describe('File', function() {
});
});

it('should confirm the abort method exists', function(done) {
var reqStream = through();

file.bucket.storage.makeAuthenticatedRequest_ = function() {
return reqStream;
};

var readStream = file.createReadStream();
readStream.resume();

setImmediate(function() {
assert.doesNotThrow(function() {
reqStream.emit('error', new Error('Error.'));
setImmediate(done);
});
});
});

describe('authenticating', function() {
it('should create an authenticated request', function(done) {
var expectedPath = format('https://{host}/{b}/{o}', {
Expand Down