@@ -97,27 +97,32 @@ describe('#integration stress tests', () => {
9797 await driver . close ( )
9898 } )
9999
100- it ( 'basic' , done => {
101- const context = new Context ( driver , LOGGING_ENABLED )
102- const commands = createCommands ( context )
100+ it (
101+ 'basic' ,
102+ done => {
103+ const context = new Context ( driver , LOGGING_ENABLED )
104+ const commands = createCommands ( context )
103105
104- console . time ( 'Basic-stress-test' )
105- parallelLimit ( commands , TEST_MODE . parallelism , error => {
106- console . timeEnd ( 'Basic-stress-test' )
106+ console . time ( 'Basic-stress-test' )
107+ parallelLimit ( commands , TEST_MODE . parallelism , error => {
108+ console . timeEnd ( 'Basic-stress-test' )
107109
108- console . log ( 'Read statistics: ' , context . readServersWithQueryCount )
109- console . log ( 'Write statistics: ' , context . writeServersWithQueryCount )
110+ console . log ( 'Read statistics: ' , context . readServersWithQueryCount )
111+ console . log ( 'Write statistics: ' , context . writeServersWithQueryCount )
110112
111- if ( error ) {
112- done . fail ( error )
113- }
113+ if ( error ) {
114+ done . fail ( error )
115+ }
114116
115- verifyServers ( context )
116- . then ( ( ) => verifyNodeCount ( context ) )
117- . then ( ( ) => done ( ) )
118- . catch ( error => done . fail ( error ) )
119- } )
120- } )
117+ verifyServers ( context )
118+ . then ( ( ) => verifyCommandsRun ( context , TEST_MODE . commandsCount ) )
119+ . then ( ( ) => verifyNodeCount ( context ) )
120+ . then ( ( ) => done ( ) )
121+ . catch ( error => done . fail ( error ) )
122+ } )
123+ } ,
124+ TEST_MODE . maxRunTimeMs
125+ )
121126
122127 function createCommands ( context ) {
123128 const uniqueCommands = createUniqueCommands ( context )
@@ -276,7 +281,7 @@ describe('#integration stress tests', () => {
276281 context . log ( commandId , 'Query completed successfully' )
277282
278283 return session . close ( ) . then ( ( ) => {
279- const possibleError = verifyQueryResult ( result )
284+ const possibleError = verifyQueryResult ( result , context )
280285 callback ( possibleError )
281286 } )
282287 } )
@@ -316,10 +321,19 @@ describe('#integration stress tests', () => {
316321 context . queryCompleted ( result , accessMode , session . lastBookmark ( ) )
317322 context . log ( commandId , 'Transaction function executed successfully' )
318323
319- return session . close ( ) . then ( ( ) => {
320- const possibleError = verifyQueryResult ( result )
321- callback ( possibleError )
322- } )
324+ return session
325+ . close ( )
326+ . then ( ( ) => {
327+ const possibleError = verifyQueryResult ( result , context )
328+ callback ( possibleError )
329+ } )
330+ . catch ( error => {
331+ context . log (
332+ commandId ,
333+ `Error closing the session ${ JSON . stringify ( error ) } `
334+ )
335+ callback ( error )
336+ } )
323337 } )
324338 . catch ( error => {
325339 context . log (
@@ -355,7 +369,7 @@ describe('#integration stress tests', () => {
355369
356370 tx . run ( query , params )
357371 . then ( result => {
358- let commandError = verifyQueryResult ( result )
372+ let commandError = verifyQueryResult ( result , context )
359373
360374 tx . commit ( )
361375 . catch ( commitError => {
@@ -388,10 +402,13 @@ describe('#integration stress tests', () => {
388402 }
389403 }
390404
391- function verifyQueryResult ( result ) {
405+ function verifyQueryResult ( result , context ) {
392406 if ( ! result ) {
393407 return new Error ( 'Received undefined result' )
394- } else if ( result . records . length === 0 ) {
408+ } else if (
409+ result . records . length === 0 &&
410+ context . writeCommandsRun < TEST_MODE . parallelism
411+ ) {
395412 // it is ok to receive no nodes back for read queries at the beginning of the test
396413 return null
397414 } else if ( result . records . length === 1 ) {
@@ -424,6 +441,14 @@ describe('#integration stress tests', () => {
424441 return null
425442 }
426443
444+ function verifyCommandsRun ( context , expectedCommandsRun ) {
445+ if ( context . commandsRun !== expectedCommandsRun ) {
446+ throw new Error (
447+ `Unexpected commands run: ${ context . commandsRun } , expected: ${ expectedCommandsRun } `
448+ )
449+ }
450+ }
451+
427452 function verifyNodeCount ( context ) {
428453 const expectedNodeCount = context . createdNodesCount
429454
@@ -507,10 +532,10 @@ describe('#integration stress tests', () => {
507532
508533 function fetchClusterAddresses ( context ) {
509534 const session = context . driver . session ( )
510- return session . run ( 'CALL dbms.cluster.overview()' ) . then ( result =>
511- session . close ( ) . then ( ( ) => {
535+ return session
536+ . readTransaction ( tx => tx . run ( 'CALL dbms.cluster.overview()' ) )
537+ . then ( result => {
512538 const records = result . records
513-
514539 const supportsMultiDb = protocolVersion >= 4.0
515540 const followers = supportsMultiDb
516541 ? addressesForMultiDb ( records , 'FOLLOWER' )
@@ -519,9 +544,10 @@ describe('#integration stress tests', () => {
519544 ? addressesForMultiDb ( records , 'READ_REPLICA' )
520545 : addressesWithRole ( records , 'READ_REPLICA' )
521546
522- return new ClusterAddresses ( followers , readReplicas )
547+ return session
548+ . close ( )
549+ . then ( ( ) => new ClusterAddresses ( followers , readReplicas ) )
523550 } )
524- )
525551 }
526552
527553 function addressesForMultiDb ( records , role , db = 'neo4j' ) {
@@ -631,6 +657,20 @@ describe('#integration stress tests', () => {
631657 this . protocolVersion = null
632658 }
633659
660+ get commandsRun ( ) {
661+ return [
662+ ...Object . values ( this . readServersWithQueryCount ) ,
663+ ...Object . values ( this . writeServersWithQueryCount )
664+ ] . reduce ( ( a , b ) => a + b , 0 )
665+ }
666+
667+ get writeCommandsRun ( ) {
668+ return [ ...Object . values ( this . writeServersWithQueryCount ) ] . reduce (
669+ ( a , b ) => a + b ,
670+ 0
671+ )
672+ }
673+
634674 queryCompleted ( result , accessMode , bookmark ) {
635675 const serverInfo = result . summary . server
636676 this . protocolVersion = serverInfo . protocolVersion
0 commit comments