Skip to content
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
6 changes: 1 addition & 5 deletions lib/datastore/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,8 @@ Transaction.prototype.rollback = function(callback) {
var req = new pb.RollbackRequest({ transaction: this.id });
var res = pb.RollbackResponse;
this.makeReq('rollback', req, res, function(err) {
if (err) {
callback(err);
return;
}
that.isFinalized = true;
callback(null);
callback(err || null);
});
};

Expand Down
40 changes: 28 additions & 12 deletions test/datastore/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,34 @@ describe('Transaction', function() {
transaction.begin(done);
});

it('should rollback', function(done) {
transaction.id = 'some-id';
transaction.makeReq = function(method, proto, respType, callback) {
assert.equal(method, 'rollback');
assert.equal(
proto.transaction.toBase64(),
new Buffer('some-id').toString('base64'));
callback();
};
transaction.rollback(function() {
assert.equal(transaction.isFinalized, true);
done();
describe('rollback', function() {
beforeEach(function() {
transaction.id = 'transaction-id';
});

it('should rollback', function(done) {
transaction.makeReq = function(method, proto, respType, callback) {
var base64Id = new Buffer(transaction.id).toString('base64');
assert.equal(method, 'rollback');
assert.equal(proto.transaction.toBase64(), base64Id);
callback();
};
transaction.rollback(function() {
assert.equal(transaction.isFinalized, true);
done();
});
});

it('should mark as `finalized` when rollback errors', function(done) {
var error = new Error('rollback error');
transaction.makeReq = function(method, proto, respType, callback) {
callback(error);
};
transaction.rollback(function(err) {
assert.equal(err, error);
assert.equal(transaction.isFinalized, true);
done();
});
});
});

Expand Down