Skip to content

Commit

Permalink
spanner: fix stream destroy bug (#2358)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop authored and stephenplusplus committed Jun 5, 2017
1 parent 925e651 commit 03c276d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/spanner/src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Transaction.prototype.requestStream = function(config) {
return;
}

requestStream.destroy();
requestStream.end();
userStream.destroy();

if (self.shouldRetry_(err)) {
Expand Down
20 changes: 18 additions & 2 deletions packages/spanner/test/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,14 @@ describe('Transaction', function() {
var error = { code: 10 };
var stream;

var end = fakeStream.end;
var ended = false;

fakeStream.end = function() {
ended = true;
return end.call(fakeStream);
};

transaction.shouldRetry_ = function(err) {
assert.strictEqual(err, error);
return true;
Expand All @@ -620,7 +628,7 @@ describe('Transaction', function() {
transaction.runFn_ = done; // should not be called

transaction.retry_ = function() {
assert(fakeStream._destroyed);
assert(ended);
assert(stream._destroyed);
done();
};
Expand All @@ -635,6 +643,14 @@ describe('Transaction', function() {
var error = { code: 10 };
var stream;

var end = fakeStream.end;
var ended = false;

fakeStream.end = function() {
ended = true;
return end.call(fakeStream);
};

var deadlineError = {};
var createDeadlineError = Transaction.createDeadlineError_;

Expand All @@ -652,7 +668,7 @@ describe('Transaction', function() {

transaction.runFn_ = function(err) {
assert.strictEqual(err, deadlineError);
assert(fakeStream._destroyed);
assert(ended);
assert(stream._destroyed);

Transaction.createDeadlineError_ = createDeadlineError;
Expand Down

0 comments on commit 03c276d

Please sign in to comment.