Skip to content

Commit c719102

Browse files
authored
Make the stress test more reliable
Avoid session.run usage Treat the session.close() exception in the command. Check the number of commands run
1 parent 3d43e2e commit c719102

File tree

1 file changed

+49
-13
lines changed

1 file changed

+49
-13
lines changed

test/stress.test.js

+49-13
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ describe('#integration stress tests', () => {
110110
}
111111

112112
verifyServers(context)
113+
.then(() => verifyCommandsRun(context, TEST_MODE.commandsCount))
113114
.then(() => verifyNodeCount(context))
114115
.then(() => done())
115116
.catch(error => done.fail(error))
@@ -275,7 +276,7 @@ describe('#integration stress tests', () => {
275276
context.log(commandId, 'Query completed successfully')
276277

277278
return session.close().then(() => {
278-
const possibleError = verifyQueryResult(result)
279+
const possibleError = verifyQueryResult(result, context)
279280
callback(possibleError)
280281
})
281282
})
@@ -315,10 +316,19 @@ describe('#integration stress tests', () => {
315316
context.queryCompleted(result, accessMode, session.lastBookmark())
316317
context.log(commandId, 'Transaction function executed successfully')
317318

318-
return session.close().then(() => {
319-
const possibleError = verifyQueryResult(result)
320-
callback(possibleError)
321-
})
319+
return session
320+
.close()
321+
.then(() => {
322+
const possibleError = verifyQueryResult(result, context)
323+
callback(possibleError)
324+
})
325+
.catch(error => {
326+
context.log(
327+
commandId,
328+
`Error closing the session ${JSON.stringify(error)}`
329+
)
330+
callback(error)
331+
})
322332
})
323333
.catch(error => {
324334
context.log(
@@ -354,7 +364,7 @@ describe('#integration stress tests', () => {
354364

355365
tx.run(query, params)
356366
.then(result => {
357-
let commandError = verifyQueryResult(result)
367+
let commandError = verifyQueryResult(result, context)
358368

359369
tx.commit()
360370
.catch(commitError => {
@@ -387,10 +397,13 @@ describe('#integration stress tests', () => {
387397
}
388398
}
389399

390-
function verifyQueryResult (result) {
400+
function verifyQueryResult (result, context) {
391401
if (!result) {
392402
return new Error('Received undefined result')
393-
} else if (result.records.length === 0) {
403+
} else if (
404+
result.records.length === 0 &&
405+
context.writeCommandsRun < TEST_MODE.parallelism
406+
) {
394407
// it is ok to receive no nodes back for read queries at the beginning of the test
395408
return null
396409
} else if (result.records.length === 1) {
@@ -423,6 +436,14 @@ describe('#integration stress tests', () => {
423436
return null
424437
}
425438

439+
function verifyCommandsRun (context, expectedCommandsRun) {
440+
if (context.commandsRun !== expectedCommandsRun) {
441+
throw new Error(
442+
`Unexpected commands run: ${context.commandsRun}, expected: ${expectedCommandsRun}`
443+
)
444+
}
445+
}
446+
426447
function verifyNodeCount (context) {
427448
const expectedNodeCount = context.createdNodesCount
428449

@@ -506,10 +527,10 @@ describe('#integration stress tests', () => {
506527

507528
function fetchClusterAddresses (context) {
508529
const session = context.driver.session()
509-
return session.run('CALL dbms.cluster.overview()').then(result =>
510-
session.close().then(() => {
530+
return session
531+
.readTransaction(tx => tx.run('CALL dbms.cluster.overview()'))
532+
.then(result => {
511533
const records = result.records
512-
513534
const supportsMultiDb = protocolVersion >= 4.0
514535
const followers = supportsMultiDb
515536
? addressesForMultiDb(records, 'FOLLOWER')
@@ -518,9 +539,10 @@ describe('#integration stress tests', () => {
518539
? addressesForMultiDb(records, 'READ_REPLICA')
519540
: addressesWithRole(records, 'READ_REPLICA')
520541

521-
return new ClusterAddresses(followers, readReplicas)
542+
return session
543+
.close()
544+
.then(() => new ClusterAddresses(followers, readReplicas))
522545
})
523-
)
524546
}
525547

526548
function addressesForMultiDb (records, role, db = 'neo4j') {
@@ -630,6 +652,20 @@ describe('#integration stress tests', () => {
630652
this.protocolVersion = null
631653
}
632654

655+
get commandsRun () {
656+
return [
657+
...Object.values(this.readServersWithQueryCount),
658+
...Object.values(this.writeServersWithQueryCount)
659+
].reduce((a, b) => a + b, 0)
660+
}
661+
662+
get writeCommandsRun () {
663+
return [...Object.values(this.writeServersWithQueryCount)].reduce(
664+
(a, b) => a + b,
665+
0
666+
)
667+
}
668+
633669
queryCompleted (result, accessMode, bookmark) {
634670
const serverInfo = result.summary.server
635671
this.protocolVersion = serverInfo.protocolVersion

0 commit comments

Comments
 (0)