Skip to content

Commit a87fd0b

Browse files
committed
Add tests to verify connection error on commit behavior
1 parent 6e48356 commit a87fd0b

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

test/internal/node/direct.driver.boltkit.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import neo4j from '../../../src/v1';
2121
import {READ, WRITE} from '../../../src/v1/driver';
2222
import boltStub from '../bolt-stub';
23+
import { SERVICE_UNAVAILABLE } from '../../../src/v1/error';
2324

2425
describe('direct driver with stub server', () => {
2526

@@ -372,4 +373,46 @@ describe('direct driver with stub server', () => {
372373
}).catch(error => done.fail(error));
373374
});
374375
});
376+
377+
describe('should fail if commit fails due to broken connection', () => {
378+
it('v1', done => {
379+
verifyFailureOnConnectionFailureWhenExplicitTransactionIsCommitted('v1', done);
380+
});
381+
382+
it('v3', done => {
383+
verifyFailureOnConnectionFailureWhenExplicitTransactionIsCommitted('v3', done);
384+
});
385+
});
386+
387+
function verifyFailureOnConnectionFailureWhenExplicitTransactionIsCommitted(version, done) {
388+
if (!boltStub.supported) {
389+
done();
390+
return;
391+
}
392+
393+
const server = boltStub.start(`./test/resources/boltstub/connection_error_on_commit_${version}.script`, 9001);
394+
395+
boltStub.run(() => {
396+
const driver = boltStub.newDriver('bolt://127.0.0.1:9001');
397+
const session = driver.session();
398+
399+
const writeTx = session.beginTransaction();
400+
401+
writeTx.run('CREATE (n {name: \'Bob\'})').then(() =>
402+
writeTx.commit().then(result => fail('expected an error'), (error) => {
403+
expect(error.code).toBe(SERVICE_UNAVAILABLE);
404+
expect(error.message).toContain('Connection was closed by server');
405+
})
406+
).finally(() =>
407+
session.close(() => {
408+
driver.close();
409+
410+
server.exit(code => {
411+
expect(code).toEqual(0);
412+
done();
413+
});
414+
})).catch(error => done.fail(error));
415+
}
416+
);
417+
}
375418
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
!: BOLT 1
2+
!: AUTO INIT
3+
!: AUTO RESET
4+
5+
C: RUN "BEGIN" {}
6+
PULL_ALL
7+
RUN "CREATE (n {name: 'Bob'})" {}
8+
PULL_ALL
9+
S: SUCCESS {}
10+
SUCCESS {}
11+
SUCCESS {}
12+
SUCCESS {}
13+
C: RUN "COMMIT" {}
14+
PULL_ALL
15+
S: <EXIT>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
!: BOLT 3
2+
!: AUTO HELLO
3+
!: AUTO RESET
4+
5+
C: BEGIN {}
6+
S: SUCCESS {}
7+
C: RUN "CREATE (n {name: 'Bob'})" {} {}
8+
PULL_ALL
9+
S: SUCCESS {}
10+
SUCCESS {}
11+
C: COMMIT
12+
S: <EXIT>

0 commit comments

Comments
 (0)