Skip to content

Commit 5fed2fa

Browse files
authored
Merge pull request #421 from lutovich/1.7-connect-timeout-example
Add connection timeout example
2 parents fbcf676 + bc8f31e commit 5fed2fa

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

test/v1/bolt-v3.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@ describe('Bolt V3 API', () => {
9292
session.run('MATCH (n:Node) SET n.prop = $newValue', {newValue: 2}, {timeout: 1})
9393
.then(() => done.fail('Failure expected'))
9494
.catch(error => {
95-
expect(error.code.indexOf('TransientError')).toBeGreaterThan(0);
96-
expect(error.message.indexOf('transaction has been terminated')).toBeGreaterThan(0);
95+
const hasExpectedCode = error.code.indexOf('TransientError') !== -1;
96+
const hasExpectedMessage = error.message.indexOf('transaction has been terminated') !== -1;
97+
if (!hasExpectedCode || !hasExpectedMessage) {
98+
console.log(`Unexpected error with code ${error.code}`, error);
99+
}
100+
expect(hasExpectedCode).toBeTruthy();
101+
expect(hasExpectedMessage).toBeTruthy();
97102

98103
tx.rollback()
99104
.then(() => otherSession.close())

test/v1/examples.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ describe('examples', () => {
124124
};
125125
});
126126

127+
it('config connection timeout example', done => {
128+
// tag::config-connection-timeout[]
129+
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password),
130+
{
131+
connectionTimeout: 20 * 1000, // 20 seconds
132+
}
133+
);
134+
// end::config-connection-timeout[]
135+
136+
driver.onCompleted = () => {
137+
driver.close();
138+
done();
139+
};
140+
});
141+
127142
it('config load balancing example', done => {
128143
// tag::config-load-balancing-strategy[]
129144
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password),

0 commit comments

Comments
 (0)