@@ -97,27 +97,32 @@ describe('#integration stress tests', () => {
97
97
await driver . close ( )
98
98
} )
99
99
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 )
103
105
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' )
107
109
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 )
110
112
111
- if ( error ) {
112
- done . fail ( error )
113
- }
113
+ if ( error ) {
114
+ done . fail ( error )
115
+ }
114
116
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
+ )
121
126
122
127
function createCommands ( context ) {
123
128
const uniqueCommands = createUniqueCommands ( context )
@@ -276,7 +281,7 @@ describe('#integration stress tests', () => {
276
281
context . log ( commandId , 'Query completed successfully' )
277
282
278
283
return session . close ( ) . then ( ( ) => {
279
- const possibleError = verifyQueryResult ( result )
284
+ const possibleError = verifyQueryResult ( result , context )
280
285
callback ( possibleError )
281
286
} )
282
287
} )
@@ -316,10 +321,19 @@ describe('#integration stress tests', () => {
316
321
context . queryCompleted ( result , accessMode , session . lastBookmark ( ) )
317
322
context . log ( commandId , 'Transaction function executed successfully' )
318
323
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
+ } )
323
337
} )
324
338
. catch ( error => {
325
339
context . log (
@@ -355,7 +369,7 @@ describe('#integration stress tests', () => {
355
369
356
370
tx . run ( query , params )
357
371
. then ( result => {
358
- let commandError = verifyQueryResult ( result )
372
+ let commandError = verifyQueryResult ( result , context )
359
373
360
374
tx . commit ( )
361
375
. catch ( commitError => {
@@ -388,10 +402,13 @@ describe('#integration stress tests', () => {
388
402
}
389
403
}
390
404
391
- function verifyQueryResult ( result ) {
405
+ function verifyQueryResult ( result , context ) {
392
406
if ( ! result ) {
393
407
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
+ ) {
395
412
// it is ok to receive no nodes back for read queries at the beginning of the test
396
413
return null
397
414
} else if ( result . records . length === 1 ) {
@@ -424,6 +441,14 @@ describe('#integration stress tests', () => {
424
441
return null
425
442
}
426
443
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
+
427
452
function verifyNodeCount ( context ) {
428
453
const expectedNodeCount = context . createdNodesCount
429
454
@@ -507,10 +532,10 @@ describe('#integration stress tests', () => {
507
532
508
533
function fetchClusterAddresses ( context ) {
509
534
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 => {
512
538
const records = result . records
513
-
514
539
const supportsMultiDb = protocolVersion >= 4.0
515
540
const followers = supportsMultiDb
516
541
? addressesForMultiDb ( records , 'FOLLOWER' )
@@ -519,9 +544,10 @@ describe('#integration stress tests', () => {
519
544
? addressesForMultiDb ( records , 'READ_REPLICA' )
520
545
: addressesWithRole ( records , 'READ_REPLICA' )
521
546
522
- return new ClusterAddresses ( followers , readReplicas )
547
+ return session
548
+ . close ( )
549
+ . then ( ( ) => new ClusterAddresses ( followers , readReplicas ) )
523
550
} )
524
- )
525
551
}
526
552
527
553
function addressesForMultiDb ( records , role , db = 'neo4j' ) {
@@ -631,6 +657,20 @@ describe('#integration stress tests', () => {
631
657
this . protocolVersion = null
632
658
}
633
659
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
+
634
674
queryCompleted ( result , accessMode , bookmark ) {
635
675
const serverInfo = result . summary . server
636
676
this . protocolVersion = serverInfo . protocolVersion
0 commit comments