@@ -44,19 +44,21 @@ describe('neo4j instrumentation', function () {
4444 driver = neo4j . driver ( 'bolt://localhost:11011' , neo4j . auth . basic ( 'neo4j' , 'test' ) , {
4545 disableLosslessIntegers : true ,
4646 } ) ;
47-
47+
4848 let keepChecking = true ;
49- const timeoutId = setTimeout ( ( ) => { keepChecking = false } , 8000 ) ;
49+ const timeoutId = setTimeout ( ( ) => {
50+ keepChecking = false ;
51+ } , 8000 ) ;
5052 while ( keepChecking ) {
5153 try {
5254 await driver . verifyConnectivity ( ) ;
5355 clearTimeout ( timeoutId ) ;
5456 return ;
5557 } catch ( err ) {
5658 await new Promise ( ( res ) => setTimeout ( res , 1000 ) ) ;
57- }
59+ }
5860 }
59- throw new Error ( 'Could not connect to neo4j in allowed time frame' )
61+ throw new Error ( 'Could not connect to neo4j in allowed time frame' ) ;
6062 } ) ;
6163
6264 after ( async ( ) => {
@@ -147,7 +149,7 @@ describe('neo4j instrumentation', function () {
147149
148150 it ( 'when passing "onKeys" and onCompleted, span is closed in onCompleted, and response hook is called' , ( done ) => {
149151 instrumentation . disable ( ) ;
150- instrumentation . setConfig ( { responseHook : ( span ) => span . setAttribute ( 'test' , 'cool' ) } ) ;
152+ instrumentation . setConfig ( { responseHook : ( span ) => span . setAttribute ( 'test' , 'cool' ) } ) ;
151153 instrumentation . enable ( ) ;
152154
153155 driver
@@ -163,7 +165,7 @@ describe('neo4j instrumentation', function () {
163165 assertSpan ( span ) ;
164166 expect ( span . attributes [ 'test' ] ) . toBe ( 'cool' ) ;
165167 done ( ) ;
166- }
168+ } ,
167169 } ) ;
168170 } ) ;
169171
@@ -465,4 +467,34 @@ describe('neo4j instrumentation', function () {
465467 } ) ;
466468 } ) ;
467469 } ) ;
470+
471+ describe ( 'routing mode' , ( ) => {
472+ // When the connection string starts with "neo4j" routing mode is used
473+ let routingDriver : Driver ;
474+ const version = require ( 'neo4j-driver/package.json' ) . version ;
475+ const shouldCheck = ! [ '4.0.0' , '4.0.1' , '4.0.2' ] . includes ( version )
476+
477+ before ( ( ) => {
478+ if ( shouldCheck ) {
479+ routingDriver = neo4j . driver ( 'neo4j://localhost:11011' , neo4j . auth . basic ( 'neo4j' , 'test' ) ) ;
480+ }
481+ } ) ;
482+
483+ after ( async ( ) => {
484+ shouldCheck && await routingDriver . close ( ) ;
485+ } ) ;
486+
487+ it ( 'instruments as expected in routing mode' , async ( ) => {
488+ if ( ! shouldCheck ) {
489+ // Versions 4.0.0, 4.0.1 and 4.0.2 of neo4j-driver don't allow connection to local neo4j in routing mode.
490+ console . log ( `Skipping unsupported test for version ${ version } ` )
491+ return ;
492+ }
493+
494+ await routingDriver . session ( ) . run ( 'CREATE (n:MyLabel) RETURN n' ) ;
495+
496+ const span = getSingleSpan ( ) ;
497+ assertSpan ( span ) ;
498+ } ) ;
499+ } ) ;
468500} ) ;
0 commit comments