Skip to content

Commit bf34d90

Browse files
authored
Merge pull request #291 from lutovich/1.5-always-test-boltkit
Refactor boltstub, always run related tests
2 parents 6b674a7 + c13f2dc commit bf34d90

File tree

52 files changed

+473
-482
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+473
-482
lines changed

gulpfile.babel.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,6 @@ gulp.task('test-nodejs', ['install-driver-into-sandbox'], function () {
170170
})).on('end', logActiveNodeHandles);
171171
});
172172

173-
gulp.task('test-boltkit', ['nodejs'], function () {
174-
return gulp.src('test/**/*.boltkit.it.js')
175-
.pipe(jasmine({
176-
includeStackTrace: true,
177-
verbose: true
178-
})).on('end', logActiveNodeHandles);
179-
});
180-
181173
gulp.task('test-browser', function (cb) {
182174
runSequence('all', 'run-browser-test', cb)
183175
});

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "neo4j-driver",
3-
"version": "1.4.1-dev",
4-
"description": "Connect to Neo4j 3.1.0 and up from JavaScript",
3+
"version": "1.5.0-dev",
4+
"description": "Connect to Neo4j 3.0.0 and up from JavaScript",
55
"author": "Neo Technology Inc.",
66
"license": "Apache-2.0",
77
"repository": {
@@ -10,7 +10,6 @@
1010
},
1111
"scripts": {
1212
"test": "gulp test",
13-
"boltkit": "gulp test-boltkit",
1413
"build": "gulp all",
1514
"start-neo4j": "gulp start-neo4j",
1615
"stop-neo4j": "gulp stop-neo4j",

test/internal/bolt-stub.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* Copyright (c) 2002-2017 "Neo Technology,","
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import sharedNeo4j from './shared-neo4j';
21+
import neo4j from '../../src/v1/index';
22+
23+
class UnsupportedBoltStub {
24+
25+
start(script, port) {
26+
throw new Error('BoltStub: unable to start, unavailable on this platform');
27+
}
28+
29+
startWithTemplate(scriptTemplate, parameters, port) {
30+
throw new Error('BoltStub: unable to start with template, unavailable on this platform');
31+
}
32+
33+
run(callback) {
34+
throw new Error('BoltStub: unable to run, unavailable on this platform');
35+
}
36+
}
37+
38+
const verbose = false; // for debugging purposes
39+
40+
class SupportedBoltStub extends UnsupportedBoltStub {
41+
42+
constructor() {
43+
super();
44+
this._childProcess = require('child_process');
45+
this._mustache = require('mustache');
46+
this._fs = require('fs');
47+
this._tmp = require('tmp');
48+
}
49+
50+
static create() {
51+
try {
52+
return new SupportedBoltStub();
53+
} catch (e) {
54+
return null;
55+
}
56+
}
57+
58+
start(script, port) {
59+
const boltStub = this._childProcess.spawn('boltstub', ['-v', port, script]);
60+
61+
if (verbose) {
62+
boltStub.stdout.on('data', (data) => {
63+
console.log(`${data}`);
64+
});
65+
boltStub.stderr.on('data', (data) => {
66+
console.log(`${data}`);
67+
});
68+
boltStub.on('end', data => {
69+
console.log(data);
70+
});
71+
}
72+
73+
let exitCode = -1;
74+
boltStub.on('close', code => {
75+
exitCode = code;
76+
});
77+
78+
boltStub.on('error', error => {
79+
console.log('Failed to start child process:' + error);
80+
});
81+
82+
return new StubServer(() => exitCode);
83+
}
84+
85+
startWithTemplate(scriptTemplate, parameters, port) {
86+
const template = this._fs.readFileSync(scriptTemplate, 'utf-8');
87+
const scriptContents = this._mustache.render(template, parameters);
88+
const script = this._tmp.fileSync().name;
89+
this._fs.writeFileSync(script, scriptContents, 'utf-8');
90+
return this.start(script, port);
91+
}
92+
93+
run(callback) {
94+
// wait to make sure boltstub is started before running user code
95+
setTimeout(callback, 1000);
96+
}
97+
}
98+
99+
class StubServer {
100+
101+
constructor(exitCodeSupplier) {
102+
this._exitCodeSupplier = exitCodeSupplier;
103+
this.exit.bind(this);
104+
}
105+
106+
exit(callback) {
107+
// give process some time to exit
108+
setTimeout(() => {
109+
callback(this._exitCodeSupplier());
110+
}, 1000);
111+
}
112+
}
113+
114+
function newDriver(url) {
115+
// boltstub currently does not support encryption, create driver with encryption turned off
116+
const config = {
117+
encrypted: 'ENCRYPTION_OFF'
118+
};
119+
return neo4j.driver(url, sharedNeo4j.authToken, config);
120+
}
121+
122+
const supportedStub = SupportedBoltStub.create();
123+
const supported = supportedStub != null;
124+
const stub = supported ? supportedStub : new UnsupportedBoltStub();
125+
126+
export default {
127+
supported: supported,
128+
start: stub.start.bind(stub),
129+
startWithTemplate: stub.startWithTemplate.bind(stub),
130+
run: stub.run.bind(stub),
131+
newDriver: newDriver
132+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
!: AUTO RESET
22
!: AUTO PULL_ALL
33

4-
C: INIT "neo4j-javascript/0.0.0-dev" {"credentials": "neo4j", "scheme": "basic", "principal": "neo4j"}
4+
C: INIT "neo4j-javascript/0.0.0-dev" {"credentials": "password", "scheme": "basic", "principal": "neo4j"}
55
S: FAILURE {"code": "Neo.ClientError.Security.Unauthorized", "message": "Some server auth error message"}
66
S: <EXIT>

test/resources/boltkit/read_server_with_version.script renamed to test/resources/boltstub/read_server_with_version.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
!: AUTO RESET
22
!: AUTO PULL_ALL
33

4-
C: INIT "neo4j-javascript/0.0.0-dev" {"credentials": "neo4j", "scheme": "basic", "principal": "neo4j"}
4+
C: INIT "neo4j-javascript/0.0.0-dev" {"credentials": "password", "scheme": "basic", "principal": "neo4j"}
55
S: SUCCESS {"server": "Neo4j/8.8.8"}
66
C: RUN "MATCH (n) RETURN n.name" {}
77
PULL_ALL

test/resources/boltkit/return_x.script renamed to test/resources/boltstub/return_x.script

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
!: AUTO INIT
22
!: AUTO RESET
3-
!: AUTO RUN "RETURN 1 // JavaDriver poll to test connection" {}
43
!: AUTO PULL_ALL
54

65
C: RUN "RETURN {x}" {"x": 1}

test/resources/boltkit/write_server_with_version.script renamed to test/resources/boltstub/write_server_with_version.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
!: AUTO RESET
22
!: AUTO PULL_ALL
33

4-
C: INIT "neo4j-javascript/0.0.0-dev" {"credentials": "neo4j", "scheme": "basic", "principal": "neo4j"}
4+
C: INIT "neo4j-javascript/0.0.0-dev" {"credentials": "password", "scheme": "basic", "principal": "neo4j"}
55
S: SUCCESS {"server": "Neo4j/9.9.9"}
66
C: RUN "CREATE (n {name:'Bob'})" {}
77
PULL_ALL

test/v1/boltkit.js

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)