Skip to content

Commit 65950ec

Browse files
authored
Merge pull request #146 from pontusmelke/1.0-test-failures
Fixing some test failures
2 parents e3c6822 + 3c8a1bb commit 65950ec

File tree

8 files changed

+83
-36
lines changed

8 files changed

+83
-36
lines changed

src/v1/internal/connector.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ RELATIONSHIP = 0x52,
5858
UNBOUND_RELATIONSHIP = 0x72,
5959
PATH = 0x50,
6060
//sent before version negotiation
61-
MAGIC_PREAMBLE = 0x6060B017;
61+
MAGIC_PREAMBLE = 0x6060B017,
62+
DEBUG = false;
6263

6364
let URLREGEX = new RegExp([
6465
"[^/]+//", // scheme
@@ -70,6 +71,20 @@ function host( url ) {
7071
return url.match( URLREGEX )[2];
7172
}
7273

74+
/**
75+
* Very rudimentary log handling, should probably be replaced by something proper at some point.
76+
* @param actor the part that sent the message, 'S' for server and 'C' for client
77+
* @param msg the bolt message
78+
*/
79+
function log(actor, msg) {
80+
if (DEBUG) {
81+
for(var i = 2; i < arguments.length; i++) {
82+
msg += " " + JSON.stringify(arguments[i]);
83+
}
84+
console.log(actor + ":" + msg);
85+
}
86+
}
87+
7388
function port( url ) {
7489
return url.match( URLREGEX )[3];
7590
}
@@ -186,8 +201,6 @@ class Connection {
186201
this._unpacker.structMappers[UNBOUND_RELATIONSHIP] = _mappers.unboundRel;
187202
this._unpacker.structMappers[PATH] = _mappers.path;
188203

189-
190-
191204
let self = this;
192205
// TODO: Using `onmessage` and `onerror` came from the WebSocket API,
193206
// it reads poorly and has several annoying drawbacks. Swap to having
@@ -266,16 +279,19 @@ class Connection {
266279
_handleMessage( msg ) {
267280
switch( msg.signature ) {
268281
case RECORD:
282+
log("S", "RECORD", msg.fields[0]);
269283
this._currentObserver.onNext( msg.fields[0] );
270284
break;
271285
case SUCCESS:
286+
log("S", "SUCCESS", msg.fields[0]);
272287
try {
273288
this._currentObserver.onCompleted( msg.fields[0] );
274289
} finally {
275290
this._currentObserver = this._pendingObservers.shift();
276291
}
277292
break;
278293
case FAILURE:
294+
log("S", "FAILURE", msg);
279295
try {
280296
this._currentObserver.onError( msg );
281297
this._errorMsg = msg;
@@ -303,6 +319,7 @@ class Connection {
303319
}
304320
break;
305321
case IGNORED:
322+
log("S", "IGNORED");
306323
try {
307324
if (this._errorMsg && this._currentObserver.onError)
308325
this._currentObserver.onError(this._errorMsg);
@@ -319,6 +336,7 @@ class Connection {
319336

320337
/** Queue an INIT-message to be sent to the database */
321338
initialize( clientName, token, observer ) {
339+
log("C", "INIT", clientName, token);
322340
this._queueObserver(observer);
323341
this._packer.packStruct( INIT, [this._packable(clientName), this._packable(token)],
324342
(err) => this._handleFatalError(err) );
@@ -328,6 +346,7 @@ class Connection {
328346

329347
/** Queue a RUN-message to be sent to the database */
330348
run( statement, params, observer ) {
349+
log("C", "RUN", statement, params);
331350
this._queueObserver(observer);
332351
this._packer.packStruct( RUN, [this._packable(statement), this._packable(params)],
333352
(err) => this._handleFatalError(err) );
@@ -336,20 +355,23 @@ class Connection {
336355

337356
/** Queue a PULL_ALL-message to be sent to the database */
338357
pullAll( observer ) {
358+
log("C", "PULL_ALL");
339359
this._queueObserver(observer);
340360
this._packer.packStruct( PULL_ALL, [], (err) => this._handleFatalError(err) );
341361
this._chunker.messageBoundary();
342362
}
343363

344364
/** Queue a DISCARD_ALL-message to be sent to the database */
345365
discardAll( observer ) {
366+
log("C", "DISCARD_ALL");
346367
this._queueObserver(observer);
347368
this._packer.packStruct( DISCARD_ALL, [], (err) => this._handleFatalError(err) );
348369
this._chunker.messageBoundary();
349370
}
350371

351372
/** Queue a RESET-message to be sent to the database */
352373
reset( observer ) {
374+
log("C", "RESET");
353375
this._isHandlingFailure = true;
354376
let self = this;
355377
let wrappedObs = {
@@ -369,6 +391,7 @@ class Connection {
369391

370392
/** Queue a ACK_FAILURE-message to be sent to the database */
371393
_ackFailure( observer ) {
394+
log("C", "ACK_FAILURE");
372395
this._queueObserver(observer);
373396
this._packer.packStruct( ACK_FAILURE, [], (err) => this._handleFatalError(err) );
374397
this._chunker.messageBoundary();

test/internal/tls.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ var hasFeature = require("../../lib/v1/internal/features");
2525
describe('trust-signed-certificates', function() {
2626

2727
var driver;
28-
var log = console.log
28+
var log = console.log;
2929
beforeEach(function() {
3030
console.log = function () {}; // To mute deprecation message in test output
31-
})
31+
});
3232
it('should reject unknown certificates', function(done) {
3333
// Assuming we only run this test on NodeJS
3434
if( !NodeChannel.available ) {

test/v1/session.test.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@ var Session = require("../../lib/v1/session");
2323

2424
describe('session', function () {
2525

26-
var driver, session, server;
26+
var driver, session, server, originalTimeout;
2727

2828
beforeEach(function (done) {
2929
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
3030
driver.onCompleted = function (meta) {
3131
server = meta['server'];
3232
};
3333
session = driver.session();
34+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
35+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
3436

3537
session.run("MATCH (n) DETACH DELETE n").then(done);
3638
});
3739

3840
afterEach(function () {
41+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
3942
driver.close();
4043
});
4144

@@ -177,8 +180,8 @@ describe('session', function () {
177180
session.run(statement)
178181
.then(function (result) {
179182
var sum = result.summary;
180-
expect(sum.resultAvailableAfter.toInt()).toBeGreaterThan(0);
181-
expect(sum.resultConsumedAfter.toInt()).toBeGreaterThan(0);
183+
expect(sum.resultAvailableAfter.toInt()).not.toBeLessThan(0);
184+
expect(sum.resultConsumedAfter.toInt()).not.toBeLessThan(0);
182185
done();
183186
});
184187
});
@@ -313,8 +316,8 @@ describe('session', function () {
313316
.then(function (ignore) {
314317
done();
315318
});
316-
}, 1000);
317-
}, 1500);
319+
}, 500);
320+
}, 500);
318321
});
319322

320323
it('should fail nicely on unpackable values ', function (done) {

test/v1/tck/steps/authsteps.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,36 @@ module.exports = function () {
2626
var password = "password";
2727

2828
this.Given(/^a driver is configured with auth enabled and correct password is provided$/, function () {
29-
this.driver.close();
29+
if (this.driver) {
30+
this.driver.close();
31+
}
3032
this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
3133
});
3234

3335
this.Then(/^reading and writing to the database should be possible$/, function (callback) {
34-
var session = this.driver.session()
36+
var session = this.driver.session();
3537
session.run("CREATE (:label1)").then( function( ) {
3638
callback();
3739
}).catch(function(err) {callback(new Error("Rejected Promise: " + err))});
3840
});
3941

4042
this.Given(/^a driver is configured with auth enabled and the wrong password is provided$/, function () {
41-
this.driver.close();
43+
if (this.driver) {
44+
this.driver.close();
45+
}
4246
this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "wrong"));
47+
this.driver.session();
4348
});
4449

45-
this.Then(/^reading and writing to the database should not be possible$/, function (callback) {
46-
this.driver.onError = function(err) {
47-
self.err = err;
48-
};
49-
var session = this.driver.session();
50+
this.Then(/^reading and writing to the database should not be possible$/, {timeout:5000}, function (callback) {
51+
5052
var self = this;
53+
this.driver.onError = function (err) {
54+
self.err = err;
55+
callback();
56+
};
57+
58+
var session = this.driver.session();
5159
session.run("CREATE (:label1)").then( function( ) {
5260
callback(new Error("Should not be able to run session!"));
5361
}).catch( function(err) {

test/v1/tck/steps/environment.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,34 @@ var fs = require("fs");
2222

2323
module.exports = function () {
2424

25+
var driver = undefined;
26+
2527
var failedScenarios = [];
2628

29+
this.registerHandler("BeforeFeatures", function(event, next) {
30+
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
31+
32+
return next()
33+
});
34+
2735
this.Before("@reset_database", function( scenario, callback ) {
28-
this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
36+
this.driver = driver;
2937
this.session = this.driver.session();
3038
this.session.run("MATCH (n) DETACH DELETE n").then( function( ) {
31-
callback();
39+
callback();
3240
});
33-
callback();
3441
});
3542

3643
this.Before("@tls", function( scenario ) {
44+
3745
this.knownHosts1 = "known_hosts1";
3846
this.knownHosts2 = "known_hosts2";
3947
_deleteFile(this.knownHosts1);
4048
_deleteFile(this.knownHosts2);
4149
});
4250

4351
this.Before("~@reset_database", "~@tls", function( scenario, callback ) {
44-
this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
52+
this.driver = driver;
4553
this.session = this.driver.session();
4654
callback();
4755
});
@@ -50,9 +58,9 @@ module.exports = function () {
5058
this.savedValues = {};
5159
});
5260

53-
this.After(function (scenario, callback) {
54-
if (this.driver) {
55-
this.driver.close();
61+
this.After("~@error_reporting",function (scenario, callback) {
62+
if (this.session) {
63+
this.session.close();
5664
}
5765
if (!scenario.isSuccessful()) {
5866
failedScenarios.push(scenario)
@@ -64,6 +72,9 @@ module.exports = function () {
6472
});
6573

6674
this.registerHandler('AfterFeatures', function (event, callback) {
75+
if (driver) {
76+
driver.close();
77+
}
6778
if (failedScenarios.length) {
6879
for ( var i = 0; i < failedScenarios.length; i++) {
6980
console.log("FAILED! Scenario: " + failedScenarios[i].getName());

test/v1/tck/steps/erroreportingsteps.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ module.exports = function () {
3030
});
3131

3232
this.When(/^`run` a query with that same session without closing the transaction first$/, function (callback) {
33-
self = this;
33+
var self = this;
3434
this.session.run("CREATE (:n)").then(function(result) {callback()}).catch(function(err) {self.error = err; callback()})
3535
});
3636

3737
this.Then(/^it throws a `ClientException`$/, function (table) {
38-
expected = table.rows()[0][0];
38+
var expected = table.rows()[0][0];
3939
if (this.error === undefined) {
4040
throw new Error("Exepcted an error but got none.")
4141
}
@@ -57,22 +57,24 @@ module.exports = function () {
5757
});
5858

5959
this.When(/^I run a non valid cypher statement$/, function (callback) {
60-
self = this;
60+
var self = this;
6161
this.session.run("CRETE (:n)").then(function(result) {callback()}).catch(function(err) {self.error = err.fields[0]; callback()})
6262
});
6363

6464
this.When(/^I set up a driver to an incorrect port$/, function (callback) {
65-
self = this;
66-
driver = neo4j.driver("bolt://localhost:7777", neo4j.auth.basic("neo4j", "neo4j"));
67-
driver.session();
65+
var self = this;
66+
var driver = neo4j.driver("bolt://localhost:7777", neo4j.auth.basic("neo4j", "neo4j"));
6867
driver.onError = function (error) { self.error = error; callback()};
68+
driver.session();
69+
setTimeout(callback, 1000);
6970
});
7071

7172
this.When(/^I set up a driver with wrong scheme$/, function (callback) {
72-
self = this;
73-
driver = neo4j.driver("wrong://localhost:7474", neo4j.auth.basic("neo4j", "neo4j"));
73+
var self = this;
74+
var driver = neo4j.driver("wrong://localhost:7474", neo4j.auth.basic("neo4j", "neo4j"));
7475
driver.session();
7576
driver.onError = function (error) { self.error = error; callback()};
77+
driver.close();
7678
});
7779

78-
}
80+
};

test/v1/tck/steps/resultapisteps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,4 @@ this.Then(/^the `Result Summary` `Notifications` has one notification with$/, fu
235235
throw Error("No statistics mapping of: " + statementString)
236236
}
237237

238-
}
238+
};

test/v1/tck/steps/tlssteps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = function () {
5151
callback();
5252
});
5353

54-
this.Then(/^creating sessions should fail$/, function (callback) {
54+
this.Then(/^creating sessions should fail$/, {timeout: CALLBACK_TIMEOUT}, function (callback) {
5555
var session = this.driver1.session();
5656
var self = this;
5757
session.run("RETURN 1")

0 commit comments

Comments
 (0)