Skip to content

Commit 2c435d6

Browse files
committed
Fixed all the things!!!! (by closing drivers)
1 parent 9a2919c commit 2c435d6

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

test/v1/examples.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ describe('transaction', function() {
3636
session.run("MATCH (n) DETACH DELETE n").then(done);
3737
});
3838

39+
afterEach(function() {
40+
driver.close();
41+
});
42+
3943
it('should document a minimum viable snippet', function(done) {
4044
// tag::minimum-snippet[]
4145
var driver = neo4j.driver("bolt://localhost");

test/v1/session.test.js

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,39 @@ var neo4j = require("../../lib/v1");
2121
var StatementType = require("../../lib/v1/result-summary").statementType;
2222

2323
describe('session', function() {
24+
25+
var driver, session;
26+
27+
beforeEach(function(done) {
28+
driver = neo4j.driver("bolt://localhost");
29+
session = driver.session();
30+
31+
session.run("MATCH (n) DETACH DELETE n").then(done);
32+
});
33+
34+
afterEach(function() {
35+
driver.close();
36+
});
37+
2438
it('should expose basic run/subscribe ', function(done) {
2539
// Given
26-
var driver = neo4j.driver("bolt://localhost");
2740

2841
// When & Then
2942
var records = [];
30-
driver.session().run( "RETURN 1.0 AS a").subscribe( {
43+
session.run( "RETURN 1.0 AS a").subscribe( {
3144
onNext : function( record ) {
3245
records.push( record );
3346
},
3447
onCompleted : function( ) {
3548
expect( records.length ).toBe( 1 );
3649
expect( records[0]['a'] ).toBe( 1 );
37-
driver.close();
3850
done();
3951
}
4052
});
4153
});
4254

4355
it('should keep context in subscribe methods ', function(done) {
4456
// Given
45-
var driver = neo4j.driver("bolt://localhost");
4657
function myObserver(){
4758
this.local = 'hello';
4859
var privateLocal = 'hello';
@@ -53,55 +64,47 @@ describe('session', function() {
5364
this.onCompleted = function() {
5465
expect(privateLocal).toBe('hello');
5566
expect(this.local).toBe('hello');
56-
driver.close();
5767
done();
5868
}
5969
}
6070

6171
// When & Then
62-
driver.session().run( "RETURN 1.0 AS a").subscribe(new myObserver());
72+
session.run( "RETURN 1.0 AS a").subscribe(new myObserver());
6373
});
6474

6575
it('should call observers onError on error ', function(done) {
66-
// Given
67-
var driver = neo4j.driver("bolt://localhost");
6876

6977
// When & Then
7078
var records = [];
71-
driver.session().run( "RETURN 1 AS").subscribe( {
79+
session.run( "RETURN 1 AS").subscribe( {
7280
onError: function(error) {
7381
expect(error.fields.length).toBe(1);
74-
driver.close();
7582
done();
7683
}
7784
});
7885
});
7986

8087
it('should accept a statement object ', function(done) {
8188
// Given
82-
var driver = neo4j.driver("bolt://localhost");
8389
var statement = {text: "RETURN 1 = {param} AS a", parameters: {param: 1}};
8490

8591
// When & Then
8692
var records = [];
87-
driver.session().run( statement ).subscribe( {
93+
session.run( statement ).subscribe( {
8894
onNext : function( record ) {
8995
records.push( record );
9096
},
9197
onCompleted : function( ) {
9298
expect( records.length ).toBe( 1 );
9399
expect( records[0]['a'] ).toBe( true );
94-
driver.close();
95100
done();
96101
}
97102
});
98103
});
99104

100105
it('should expose basic run/then/then/then ', function(done) {
101-
// Given
102-
var driver = neo4j.driver("bolt://localhost");
103106
// When & Then
104-
driver.session().run( "RETURN 1.0 AS a")
107+
session.run( "RETURN 1.0 AS a")
105108
.then(
106109
function( records ) {
107110
expect( records.length ).toBe( 1 );
@@ -112,48 +115,42 @@ describe('session', function() {
112115
expect( records.length ).toBe( 1 );
113116
expect( records[0]['a'] ).toBe( 1 );
114117
}
115-
).then( function() { driver.close(); done(); })
118+
).then( function() { done(); })
116119
});
117120

118121
it('should expose basic run/catch ', function(done) {
119-
// Given
120-
var driver = neo4j.driver("bolt://localhost");
121122
// When & Then
122-
driver.session().run( "RETURN 1 AS").catch(
123+
session.run( "RETURN 1 AS").catch(
123124
function(error) {
124125
expect( error.fields.length).toBe(1);
125-
driver.close();
126126
done();
127127
}
128128
)
129129
});
130130

131131
it('should expose summarize method for basic metadata ', function(done) {
132132
// Given
133-
var driver = neo4j.driver("bolt://localhost");
134133
var statement = "CREATE (n:Label {prop:{prop}}) RETURN n";
135134
var params = {prop: "string"}
136135
// When & Then
137-
driver.session().run( statement, params )
136+
session.run( statement, params )
138137
.then(function(result) {
139138
var sum = result.summary;
140139
expect(sum.statement.text).toBe( statement );
141140
expect(sum.statement.parameters).toBe( params );
142141
expect(sum.updateStatistics.containsUpdates()).toBe(true);
143142
expect(sum.updateStatistics.nodesCreated()).toBe(1);
144143
expect(sum.statementType).toBe(StatementType.READ_WRITE);
145-
driver.close();
146144
done();
147145
});
148146
});
149147

150148
it('should expose plan ', function(done) {
151149
// Given
152-
var driver = neo4j.driver("bolt://localhost");
153150
var statement = "EXPLAIN CREATE (n:Label {prop:{prop}}) RETURN n";
154151
var params = {prop: "string"}
155152
// When & Then
156-
driver.session()
153+
session
157154
.run( statement, params )
158155
.then(function(result) {
159156
var sum = result.summary;
@@ -163,18 +160,16 @@ describe('session', function() {
163160
expect(sum.plan.arguments.runtime).toBe('INTERPRETED');
164161
expect(sum.plan.identifiers[0]).toBe('n');
165162
expect(sum.plan.children[0].operatorType).toBe('CreateNode');
166-
driver.close();
167163
done();
168164
});
169165
});
170166

171167
it('should expose profile ', function(done) {
172168
// Given
173-
var driver = neo4j.driver("bolt://localhost");
174169
var statement = "PROFILE MATCH (n:Label {prop:{prop}}) RETURN n";
175170
var params = {prop: "string"}
176171
// When & Then
177-
driver.session()
172+
session
178173
.run( statement, params )
179174
.then(function(result) {
180175
var sum = result.summary;
@@ -184,34 +179,29 @@ describe('session', function() {
184179
expect(sum.profile.arguments.runtime).toBe('INTERPRETED');
185180
expect(sum.profile.identifiers[0]).toBe('n');
186181
expect(sum.profile.children[0].operatorType).toBe('Filter');
187-
expect(sum.profile.rows).toBeGreaterThan(0);
182+
expect(sum.profile.rows).toBe(0);
188183
//expect(sum.profile.dbHits).toBeGreaterThan(0);
189-
driver.close();
190184
done();
191185
});
192186
});
193187

194188
it('should expose cypher notifications ', function(done) {
195189
// Given
196-
var driver = neo4j.driver("bolt://localhost");
197190
var statement = "EXPLAIN MATCH (n), (m) RETURN n, m";
198191
// When & Then
199-
driver.session()
192+
session
200193
.run( statement )
201194
.then(function(result) {
202195
var sum = result.summary;
203196
expect(sum.notifications.length).toBeGreaterThan(0);
204197
expect(sum.notifications[0].code).toBe("Neo.ClientNotification.Statement.CartesianProduct");
205198
expect(sum.notifications[0].title).toBe("This query builds a cartesian product between disconnected patterns.");
206199
expect(sum.notifications[0].position.column).toBeGreaterThan(0);
207-
driver.close();
208200
done();
209201
});
210202
});
211203

212204
it('should fail when using the session when having an open transaction', function (done) {
213-
// Given
214-
var session = neo4j.driver("bolt://localhost").session();
215205

216206
// When
217207
session.beginTransaction();
@@ -220,14 +210,12 @@ describe('session', function() {
220210
session.run("RETURN 42")
221211
.catch(function (error) {
222212
expect(error.error).toBe("Please close the currently open transaction object before running " +
223-
"more statements/transactions in the current session." )
213+
"more statements/transactions in the current session." );
224214
done();
225215
})
226216
});
227217

228218
it('should fail when opening multiple transactions', function () {
229-
// Given
230-
var session = neo4j.driver("bolt://localhost").session();
231219

232220
// When
233221
session.beginTransaction();

test/v1/transaction.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ describe('transaction', function() {
3030
session.run("MATCH (n) DETACH DELETE n").then(done);
3131
});
3232

33-
it('should handle simple transaction', function(done) {
33+
afterEach(function() {
34+
driver.close();
35+
});
36+
37+
it('should handle simple transaction', function(done) {
3438
// When
3539
var tx = session.beginTransaction();
3640
tx.run("CREATE (:TXNode1)");

0 commit comments

Comments
 (0)