Skip to content

Commit 9424ed5

Browse files
committed
Merge branch 1.7 into 1.7-webpack-support
2 parents aeedec1 + c348e6b commit 9424ed5

File tree

9 files changed

+328
-343
lines changed

9 files changed

+328
-343
lines changed

src/v1/internal/connection.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ export default class Connection {
373373
this._log.debug(`${this} closing`);
374374
}
375375

376-
if (this._protocol) {
377-
// protocol has been initialized
378-
// use it to notify the database about the upcoming close of the connection
376+
if (this._protocol && this.isOpen()) {
377+
// protocol has been initialized and this connection is healthy
378+
// notify the database about the upcoming close of the connection
379379
this._protocol.prepareToClose(NO_OP_OBSERVER);
380380
}
381381

test/browser/karma-firefox.conf.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ module.exports = function(config) {
3434
FirefoxHeadless: {
3535
base: 'Firefox',
3636
flags: [ '-headless' ],
37+
prefs: {
38+
'network.websocket.max-connections': 256 // as in Chrome
39+
}
3740
},
3841
},
3942
})

test/internal/connection.test.js

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ import {Chunker} from '../../src/v1/internal/chunking';
2424
import {alloc} from '../../src/v1/internal/node';
2525
import {Neo4jError, newError, SERVICE_UNAVAILABLE} from '../../src/v1/error';
2626
import sharedNeo4j from '../internal/shared-neo4j';
27-
import {ServerVersion} from '../../src/v1/internal/server-version';
27+
import {ServerVersion, VERSION_3_5_0} from '../../src/v1/internal/server-version';
2828
import lolex from 'lolex';
2929
import Logger from '../../src/v1/internal/logger';
3030
import StreamObserver from '../../src/v1/internal/stream-observer';
3131
import ConnectionErrorHandler from '../../src/v1/internal/connection-error-handler';
3232
import testUtils from '../internal/test-utils';
3333
import Bookmark from '../../src/v1/internal/bookmark';
3434
import TxConfig from '../../src/v1/internal/tx-config';
35-
import boltStub from '../internal/bolt-stub';
3635

3736
const ILLEGAL_MESSAGE = {signature: 42, fields: []};
3837
const SUCCESS_MESSAGE = {signature: 0x70, fields: [{}]};
@@ -347,27 +346,46 @@ describe('Connection', () => {
347346
connection._handleFatalError(newError('Hello', SERVICE_UNAVAILABLE));
348347
});
349348

350-
it('should send hello and goodbye messages', done => {
351-
if (!boltStub.supported) {
352-
done();
353-
return;
354-
}
349+
it('should send INIT/HELLO and GOODBYE messages', done => {
350+
const messages = [];
351+
connection = createConnection('bolt://localhost');
352+
recordWrittenMessages(connection, messages);
355353

356-
const server = boltStub.start('./test/resources/boltstub/hello_goodbye.script', 9001);
357-
358-
boltStub.run(() => {
359-
connection = createConnection('bolt://127.0.0.1:9001', {encrypted: false});
360-
connection.connect('single-connection/1.2.3', basicAuthToken())
361-
.then(() => {
362-
connection.close(() => {
363-
server.exit(code => {
364-
expect(code).toEqual(0);
365-
done();
366-
});
367-
});
368-
})
369-
.catch(error => done.fail(error));
370-
});
354+
connection.connect('mydriver/0.0.0', basicAuthToken())
355+
.then(() => {
356+
expect(connection.isOpen()).toBeTruthy();
357+
connection.close(() => {
358+
expect(messages.length).toBeGreaterThan(0);
359+
expect(messages[0].signature).toEqual(0x01); // first message is either INIT or HELLO
360+
361+
const serverVersion = ServerVersion.fromString(connection.server.version);
362+
if (serverVersion.compareTo(VERSION_3_5_0) >= 0) {
363+
expect(messages[messages.length - 1].signature).toEqual(0x02); // last message is GOODBYE in V3
364+
}
365+
done();
366+
});
367+
}).catch(done.fail);
368+
});
369+
370+
it('should not prepare broken connection to close', done => {
371+
connection = createConnection('bolt://localhost');
372+
373+
connection.connect('my-connection/9.9.9', basicAuthToken())
374+
.then(() => {
375+
expect(connection._protocol).toBeDefined();
376+
expect(connection._protocol).not.toBeNull();
377+
378+
// make connection seem broken
379+
connection._isBroken = true;
380+
expect(connection.isOpen()).toBeFalsy();
381+
382+
connection._protocol.prepareToClose = () => {
383+
throw new Error('Not supposed to be called');
384+
};
385+
386+
connection.close(() => done());
387+
})
388+
.catch(error => done.fail(error));
371389
});
372390

373391
function packedHandshakeMessage() {
@@ -446,4 +464,12 @@ describe('Connection', () => {
446464
return Connection.create(url, config || {}, new ConnectionErrorHandler(errorCode || SERVICE_UNAVAILABLE), Logger.noOp());
447465
}
448466

467+
function recordWrittenMessages(connection, messages) {
468+
const originalWrite = connection.write.bind(connection);
469+
connection.write = (message, observer, flush) => {
470+
messages.push(message);
471+
originalWrite(message, observer, flush);
472+
};
473+
}
474+
449475
});

0 commit comments

Comments
 (0)