Skip to content

Commit cb22768

Browse files
committed
Always close drivers in TCK tests
1 parent df7702a commit cb22768

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

test/v1/tck/steps/authsteps.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ module.exports = function () {
3131
});
3232

3333
this.Then(/^reading and writing to the database should be possible$/, function (callback) {
34-
var session = this.driver.session();
35-
session.run("CREATE (:label1)").then( function( ) {
36-
callback();
37-
}).catch(function(err) {callback(new Error("Rejected Promise: " + err))});
34+
var driver = this.driver;
35+
var session = driver.session();
36+
session.run('CREATE (:label1)').then(function () {
37+
closeDriver(driver);
38+
callback();
39+
}).catch(function (err) {
40+
closeDriver(driver);
41+
callback(new Error('Rejected Promise: ' + err));
42+
});
3843
});
3944

4045
this.Given(/^a driver is configured with auth enabled and the wrong password is provided$/, function () {
41-
if (this.driver) {
42-
this.driver.close();
43-
}
46+
closeDriver(this.driver);
4447
this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic(sharedNeo4j.username, "wrong"));
4548
this.driver.session();
4649
});
@@ -49,14 +52,17 @@ module.exports = function () {
4952

5053
var self = this;
5154
this.driver.onError = function (err) {
55+
closeDriver(self.driver);
5256
self.err = err;
5357
callback();
5458
};
5559

5660
var session = this.driver.session();
5761
session.run("CREATE (:label1)").then( function( ) {
62+
closeDriver(self.driver);
5863
callback(new Error("Should not be able to run session!"));
5964
}).catch( function(err) {
65+
closeDriver(self.driver);
6066
callback();
6167
});
6268
});
@@ -76,4 +82,10 @@ module.exports = function () {
7682
throw new Error("Wrong error code. Expected: '" + expectedCode + "'. Got: '" + code + "'");
7783
}
7884
});
85+
86+
function closeDriver(driver) {
87+
if (driver) {
88+
driver.close();
89+
}
90+
}
7991
};

test/v1/tck/steps/erroreportingsteps.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ module.exports = function () {
6565
this.When(/^I set up a driver to an incorrect port$/, function (callback) {
6666
var self = this;
6767
var driver = neo4j.driver("bolt://localhost:7777", neo4j.auth.basic(sharedNeo4j.username, sharedNeo4j.password));
68-
driver.onError = function (error) { self.error = error; callback()};
68+
driver.onSuccess = function () {
69+
driver.close();
70+
};
71+
driver.onError = function (error) {
72+
driver.close();
73+
self.error = error;
74+
callback();
75+
};
6976
driver.session().beginTransaction();
7077
setTimeout(callback, 1000);
7178
});

test/v1/tck/steps/tlssteps.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ module.exports = function () {
2020
});
2121

2222
this.Then(/^sessions should simply work$/, {timeout: CALLBACK_TIMEOUT}, function (callback) {
23-
var session = this.driver1.session();
23+
var self = this;
24+
var session = self.driver1.session();
2425
session.run("RETURN 1").then(function (result) {
2526
session.close();
27+
_closeDrivers(self.driver1, self.driver2);
2628
callback();
2729
}).catch(function (error) {
30+
_closeDrivers(self.driver1, self.driver2);
2831
console.log(error);
2932
});
3033
});
@@ -57,11 +60,13 @@ module.exports = function () {
5760
var self = this;
5861
session.run("RETURN 1")
5962
.then(function(res) {
63+
_closeDrivers(self.driver1, self.driver2);
6064
console.log(res);
6165
})
6266
.catch(function (error) {
6367
self.error = error;
6468
session.close();
69+
_closeDrivers(self.driver1, self.driver2);
6570
callback();
6671
});
6772
});
@@ -76,6 +81,9 @@ module.exports = function () {
7681
"and the driver will update the file with the new certificate. You can configure which file the driver should use " +
7782
"to store this information by setting `knownHosts` to another path in your driver configuration - " +
7883
"and you can disable encryption there as well using `encrypted:\"ENCRYPTION_OFF\"`.";
84+
85+
_closeDrivers(this.driver1, this.driver2);
86+
7987
if (this.error.message !== expected) {
8088
callback(new Error("Given and expected results does not match: " + this.error.message + " Expected " + expected));
8189
} else {
@@ -101,6 +109,7 @@ module.exports = function () {
101109
var session2 = self.driver2.session();
102110
session2.run("RETURN 1").then(function (result) {
103111
session2.close();
112+
_closeDrivers(self.driver1, self.driver2);
104113
callback();
105114
});
106115
});
@@ -157,6 +166,9 @@ module.exports = function () {
157166
"`neo4j.v1.driver(.., { trustedCertificates:['path/to/certificate.crt']}). This is a security measure to protect " +
158167
"against man-in-the-middle attacks. If you are just trying Neo4j out and are not concerned about encryption, " +
159168
"simply disable it using `encrypted=\"ENCRYPTION_OFF\"` in the driver options. Socket responded with: DEPTH_ZERO_SELF_SIGNED_CERT";
169+
170+
_closeDrivers(this.driver1, this.driver2);
171+
160172
if (this.error.message !== expected) {
161173
callback(new Error("Given and expected results does not match: " + this.error.message + " Expected " + expected));
162174
} else {
@@ -171,4 +183,13 @@ module.exports = function () {
171183
encrypted: "ENCRYPTION_ON"
172184
});
173185
}
186+
187+
function _closeDrivers() {
188+
for (var i = 0; i < arguments.length; i++) {
189+
var driver = arguments[i];
190+
if (driver) {
191+
driver.close();
192+
}
193+
}
194+
}
174195
};

0 commit comments

Comments
 (0)