Skip to content

Commit c743a4d

Browse files
committed
Change so that driver is not closed after each test
Closing the driver, shuts down all connections which creates a noice in the server logs.
1 parent 492c6fa commit c743a4d

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

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/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: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +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( ) {
3139
callback();
3240
});
3341
});
3442

3543
this.Before("@tls", function( scenario ) {
44+
3645
this.knownHosts1 = "known_hosts1";
3746
this.knownHosts2 = "known_hosts2";
3847
_deleteFile(this.knownHosts1);
3948
_deleteFile(this.knownHosts2);
4049
});
4150

4251
this.Before("~@reset_database", "~@tls", function( scenario, callback ) {
43-
this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
52+
this.driver = driver;
4453
this.session = this.driver.session();
4554
callback();
4655
});
@@ -50,8 +59,8 @@ module.exports = function () {
5059
});
5160

5261
this.After(function (scenario, callback) {
53-
if (this.driver) {
54-
this.driver.close();
62+
if (this.session) {
63+
this.session.close();
5564
}
5665
if (!scenario.isSuccessful()) {
5766
failedScenarios.push(scenario)
@@ -63,6 +72,9 @@ module.exports = function () {
6372
});
6473

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

test/v1/tck/steps/erroreportingsteps.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,23 @@ 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();
6969
});
7070

7171
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"));
72+
var self = this;
73+
var driver = neo4j.driver("wrong://localhost:7474", neo4j.auth.basic("neo4j", "neo4j"));
7474
driver.session();
7575
driver.onError = function (error) { self.error = error; callback()};
76+
driver.close();
7677
});
7778

78-
}
79+
};

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)