Skip to content

Commit 4c6ca28

Browse files
author
Zhen Li
committed
Update stress test to run with external cluster.
1 parent 988410e commit 4c6ca28

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

test/v1/stress.test.js

+36-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import parallelLimit from 'async/parallelLimit'
2323
import _ from 'lodash'
2424
import {
2525
ServerVersion,
26-
VERSION_3_2_0
26+
VERSION_4_0_0
2727
} from '../../src/v1/internal/server-version'
2828
import sharedNeo4j from '../internal/shared-neo4j'
2929

@@ -43,13 +43,22 @@ describe('stress tests', () => {
4343

4444
const READ_QUERY = 'MATCH (n) RETURN n LIMIT 1'
4545
const WRITE_QUERY =
46-
'CREATE (person:Person:Employee {name: {name}, salary: {salary}}) RETURN person'
46+
'CREATE (person:Person:Employee {name: $name, salary: $salary}) RETURN person'
4747

4848
const TEST_MODE = modeFromEnvOrDefault('STRESS_TEST_MODE')
4949
const DATABASE_URI = fromEnvOrDefault(
5050
'STRESS_TEST_DATABASE_URI',
5151
'bolt://localhost'
5252
)
53+
54+
const USERNAME = fromEnvOrDefault(
55+
'NEO4J_USERNAME',
56+
sharedNeo4j.authToken.principal
57+
)
58+
const PASSWORD = fromEnvOrDefault(
59+
'NEO4J_PASSWORD',
60+
sharedNeo4j.authToken.credentials
61+
)
5362
const LOGGING_ENABLED = fromEnvOrDefault('STRESS_TEST_LOGGING_ENABLED', false)
5463

5564
let originalTimeout
@@ -62,7 +71,11 @@ describe('stress tests', () => {
6271
const config = {
6372
logging: neo4j.logging.console(LOGGING_ENABLED ? 'debug' : 'info')
6473
}
65-
driver = neo4j.driver(DATABASE_URI, sharedNeo4j.authToken, config)
74+
driver = neo4j.driver(
75+
DATABASE_URI,
76+
neo4j.auth.basic(USERNAME, PASSWORD),
77+
config
78+
)
6679

6780
cleanupDb(driver).then(() => done())
6881
})
@@ -237,7 +250,7 @@ describe('stress tests', () => {
237250
.run(query, params)
238251
.then(result => {
239252
context.queryCompleted(result, accessMode)
240-
context.log(commandId, `Query completed successfully`)
253+
context.log(commandId, 'Query completed successfully')
241254

242255
session.close(() => {
243256
const possibleError = verifyQueryResult(result)
@@ -278,7 +291,7 @@ describe('stress tests', () => {
278291
resultPromise
279292
.then(result => {
280293
context.queryCompleted(result, accessMode, session.lastBookmark())
281-
context.log(commandId, `Transaction function executed successfully`)
294+
context.log(commandId, 'Transaction function executed successfully')
282295

283296
session.close(() => {
284297
const possibleError = verifyQueryResult(result)
@@ -328,7 +341,7 @@ describe('stress tests', () => {
328341
})
329342
.then(() => {
330343
context.queryCompleted(result, accessMode, session.lastBookmark())
331-
context.log(commandId, `Transaction committed successfully`)
344+
context.log(commandId, 'Transaction committed successfully')
332345

333346
session.close(() => {
334347
callback(commandError)
@@ -347,7 +360,7 @@ describe('stress tests', () => {
347360

348361
function verifyQueryResult (result) {
349362
if (!result) {
350-
return new Error(`Received undefined result`)
363+
return new Error('Received undefined result')
351364
} else if (result.records.length === 0) {
352365
// it is ok to receive no nodes back for read queries at the beginning of the test
353366
return null
@@ -467,13 +480,27 @@ describe('stress tests', () => {
467480
session.close()
468481
const records = result.records
469482

470-
const followers = addressesWithRole(records, 'FOLLOWER')
471-
const readReplicas = addressesWithRole(records, 'READ_REPLICA')
483+
const version = ServerVersion.fromString(result.summary.server.version)
484+
const supportsMultiDb = version.compareTo(VERSION_4_0_0) >= 0
485+
const followers = supportsMultiDb
486+
? addressesForMultiDb(records, 'FOLLOWER')
487+
: addressesWithRole(records, 'FOLLOWER')
488+
const readReplicas = supportsMultiDb
489+
? addressesForMultiDb(records, 'READ_REPLICA')
490+
: addressesWithRole(records, 'READ_REPLICA')
472491

473492
return new ClusterAddresses(followers, readReplicas)
474493
})
475494
}
476495

496+
function addressesForMultiDb (records, role, db = 'neo4j') {
497+
return _.uniq(
498+
records
499+
.filter(record => record.get('databases')[db] === role)
500+
.map(record => record.get('addresses')[0].replace('bolt://', ''))
501+
)
502+
}
503+
477504
function addressesWithRole (records, role) {
478505
return _.uniq(
479506
records

0 commit comments

Comments
 (0)