Skip to content

Commit 0e25da5

Browse files
authored
Merge pull request #416 from lutovich/1.7-flaky-tests
Fix flaky tests
2 parents e105ee4 + 59e788c commit 0e25da5

File tree

7 files changed

+297
-339
lines changed

7 files changed

+297
-339
lines changed

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: 27 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/buf';
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,25 @@ 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);
371368
});
372369

373370
function packedHandshakeMessage() {
@@ -446,4 +443,12 @@ describe('Connection', () => {
446443
return Connection.create(url, config || {}, new ConnectionErrorHandler(errorCode || SERVICE_UNAVAILABLE), Logger.noOp());
447444
}
448445

446+
function recordWrittenMessages(connection, messages) {
447+
const originalWrite = connection.write.bind(connection);
448+
connection.write = (message, observer, flush) => {
449+
messages.push(message);
450+
originalWrite(message, observer, flush);
451+
};
452+
}
453+
449454
});

0 commit comments

Comments
 (0)