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
8 changes: 8 additions & 0 deletions src/v1/internal/stream-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ class StreamObserver {
this._fieldKeys = [];
}

/**
* Mark this observer as if it has completed with no metadata.
*/
markCompleted() {
this._fieldKeys = [];
this._tail = {};
}

/**
* Will be called on errors.
* If user-provided observer is present, pass the error
Expand Down
4 changes: 1 addition & 3 deletions src/v1/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ let _states = {
return {result: _newDummyResult(observer, "COMMIT", {}), state: _states.FAILED};
},
rollback: (connectionHolder, observer) => {
observer.onError({error:
"Cannot rollback transaction, because previous statements in the " +
"transaction has failed and the transaction has already been rolled back."});
observer.markCompleted();
return {result: _newDummyResult(observer, "ROLLBACK", {}), state: _states.FAILED};
},
run: (connectionHolder, observer, statement, parameters) => {
Expand Down
12 changes: 12 additions & 0 deletions test/internal/stream-observer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ describe('StreamObserver', () => {
streamObserver.onCompleted({key: 42});
});

it('should mark as completed', done => {
const streamObserver = new StreamObserver();
streamObserver.markCompleted();

streamObserver.subscribe({
onCompleted: metadata => {
expect(metadata).toEqual({});
done();
}
});
});

});

function newStreamObserver() {
Expand Down
2 changes: 1 addition & 1 deletion test/v1/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('session', () => {
const session = driver.session();
const tx = session.beginTransaction();
tx.run('INVALID QUERY').catch(() => {
tx.rollback().catch(() => {
tx.rollback().then(() => {
session.close(() => {
driver.close();
done();
Expand Down
13 changes: 13 additions & 0 deletions test/v1/transaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,19 @@ describe('transaction', () => {
tx.rollback().then(() => done());
});

it('should allow rollback after failure', done => {
const tx = session.beginTransaction();
tx.run('WRONG QUERY')
.then(() => done.fail('Expected to fail'))
.catch(error => {
expectSyntaxError(error);

tx.rollback()
.catch(error => done.fail(error))
.then(() => done());
});
});

function expectSyntaxError(error) {
expect(error.code).toBe('Neo.ClientError.Statement.SyntaxError');
}
Expand Down