|
19 | 19 |
|
20 | 20 | import neo4j from '../src' |
21 | 21 | import sharedNeo4j from './internal/shared-neo4j' |
22 | | -import FakeConnection from './internal/fake-connection' |
23 | 22 | import lolex from 'lolex' |
24 | 23 | import { |
25 | 24 | DEFAULT_ACQUISITION_TIMEOUT, |
@@ -65,20 +64,20 @@ describe('#integration driver', () => { |
65 | 64 | driver.close() |
66 | 65 | }) |
67 | 66 |
|
68 | | - it('should handle connection errors', done => { |
| 67 | + it('should handle connection errors', async () => { |
69 | 68 | // Given |
70 | 69 | driver = neo4j.driver('bolt://local-host', sharedNeo4j.authToken) |
71 | | - |
72 | | - // Expect |
73 | | - driver.onError = error => { |
74 | | - // the error message is different whether in browser or node |
| 70 | + const session = driver.session() |
| 71 | + const txc = session.beginTransaction() |
| 72 | + try { |
| 73 | + await txc.run('RETURN 1') |
| 74 | + expect(true).toBeFalsy('exception expected') |
| 75 | + } catch (error) { |
75 | 76 | expect(error.message).not.toBeNull() |
76 | 77 | expect(error.code).toEqual(neo4j.error.SERVICE_UNAVAILABLE) |
77 | | - done() |
| 78 | + } finally { |
| 79 | + session.close() |
78 | 80 | } |
79 | | - |
80 | | - // When |
81 | | - startNewTransaction(driver) |
82 | 81 | }, 10000) |
83 | 82 |
|
84 | 83 | it('should fail with correct error message when connecting to port 80', done => { |
@@ -131,19 +130,20 @@ describe('#integration driver', () => { |
131 | 130 | }).toBeDefined() |
132 | 131 | }) |
133 | 132 |
|
134 | | - it('should fail early on wrong credentials', done => { |
| 133 | + it('should fail early on wrong credentials', async () => { |
135 | 134 | // Given |
136 | 135 | driver = neo4j.driver('bolt://localhost', wrongCredentials()) |
137 | | - |
138 | | - // Expect |
139 | | - driver.onError = err => { |
140 | | - // the error message is different whether in browser or node |
141 | | - expect(err.code).toEqual('Neo.ClientError.Security.Unauthorized') |
142 | | - done() |
| 136 | + const session = driver.session() |
| 137 | + const txc = session.beginTransaction() |
| 138 | + try { |
| 139 | + await txc.run('RETURN 1') |
| 140 | + expect(true).toBeFalsy('exception expected') |
| 141 | + } catch (error) { |
| 142 | + expect(error.message).not.toBeNull() |
| 143 | + expect(error.code).toEqual('Neo.ClientError.Security.Unauthorized') |
| 144 | + } finally { |
| 145 | + session.close() |
143 | 146 | } |
144 | | - |
145 | | - // When |
146 | | - startNewTransaction(driver) |
147 | 147 | }) |
148 | 148 |
|
149 | 149 | it('should fail queries on wrong credentials', done => { |
@@ -220,26 +220,25 @@ describe('#integration driver', () => { |
220 | 220 | }) |
221 | 221 | }) |
222 | 222 |
|
223 | | - it('should fail nicely when connecting with routing to standalone server', done => { |
| 223 | + it('should fail nicely when connecting with routing to standalone server', async () => { |
224 | 224 | if (!routingProcedureOnlyAvailableOnCores()) { |
225 | | - done() |
226 | | - return |
| 225 | + return Promise.resolve(null) |
227 | 226 | } |
228 | 227 |
|
229 | 228 | // Given |
230 | 229 | driver = neo4j.driver('neo4j://localhost', sharedNeo4j.authToken) |
231 | | - |
232 | | - // Expect |
233 | | - driver.onError = error => { |
| 230 | + const session = driver.session() |
| 231 | + try { |
| 232 | + await session.run('RETURN 1') |
| 233 | + expect(true).toBeFalsy('exception expected') |
| 234 | + } catch (error) { |
234 | 235 | expect(error.message).toContain( |
235 | 236 | 'Could not perform discovery. No routing servers available.' |
236 | 237 | ) |
237 | 238 | expect(error.code).toEqual(neo4j.error.SERVICE_UNAVAILABLE) |
238 | | - done() |
| 239 | + } finally { |
| 240 | + session.close() |
239 | 241 | } |
240 | | - |
241 | | - // When |
242 | | - startNewTransaction(driver) |
243 | 242 | }) |
244 | 243 |
|
245 | 244 | it('should have correct user agent', () => { |
@@ -267,42 +266,6 @@ describe('#integration driver', () => { |
267 | 266 | ) |
268 | 267 | }) |
269 | 268 |
|
270 | | - it('should treat closed connections as invalid', () => { |
271 | | - driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken) |
272 | | - |
273 | | - const connectionValid = driver._validateConnection( |
274 | | - new FakeConnection().closed() |
275 | | - ) |
276 | | - |
277 | | - expect(connectionValid).toBeFalsy() |
278 | | - }) |
279 | | - |
280 | | - it('should treat not old open connections as valid', () => { |
281 | | - driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken, { |
282 | | - maxConnectionLifetime: 10 |
283 | | - }) |
284 | | - |
285 | | - const connection = new FakeConnection().withCreationTimestamp(12) |
286 | | - clock = lolex.install() |
287 | | - clock.setSystemTime(20) |
288 | | - const connectionValid = driver._validateConnection(connection) |
289 | | - |
290 | | - expect(connectionValid).toBeTruthy() |
291 | | - }) |
292 | | - |
293 | | - it('should treat old open connections as invalid', () => { |
294 | | - driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken, { |
295 | | - maxConnectionLifetime: 10 |
296 | | - }) |
297 | | - |
298 | | - const connection = new FakeConnection().withCreationTimestamp(5) |
299 | | - clock = lolex.install() |
300 | | - clock.setSystemTime(20) |
301 | | - const connectionValid = driver._validateConnection(connection) |
302 | | - |
303 | | - expect(connectionValid).toBeFalsy() |
304 | | - }) |
305 | | - |
306 | 269 | it('should discard closed connections', done => { |
307 | 270 | driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken) |
308 | 271 |
|
@@ -514,7 +477,9 @@ describe('#integration driver', () => { |
514 | 477 | } |
515 | 478 |
|
516 | 479 | function openConnectionFrom (driver) { |
517 | | - return Array.from(Object.values(driver._openConnections)) |
| 480 | + return Array.from( |
| 481 | + Object.values(driver._connectionProvider._openConnections) |
| 482 | + ) |
518 | 483 | } |
519 | 484 |
|
520 | 485 | function routingProcedureOnlyAvailableOnCores () { |
|
0 commit comments