19
19
20
20
import { Notification , throwError } from 'rxjs'
21
21
import { map , materialize , toArray , concatWith } from 'rxjs/operators'
22
- import neo4j from '../../src'
22
+ import neo4j , { ResultSummary , int } from '../../src'
23
23
import RxSession from '../../src/session-rx'
24
24
import sharedNeo4j from '../internal/shared-neo4j'
25
25
import {
@@ -31,7 +31,7 @@ import {
31
31
} from 'neo4j-driver-core'
32
32
33
33
const { SERVICE_UNAVAILABLE , SESSION_EXPIRED } = error
34
- const { bookmarks } = internal
34
+ const { bookmarks, logger } = internal
35
35
36
36
describe ( '#integration rx-session' , ( ) => {
37
37
let driver
@@ -442,6 +442,111 @@ describe('#unit rx-session', () => {
442
442
} )
443
443
} )
444
444
445
+ describe ( '.run()' , ( ) => {
446
+ it ( 'should redirect run to the underline session' , ( ) => {
447
+ const capture = [ ]
448
+ const _session = {
449
+ run : ( ...args ) => {
450
+ capture . push ( args )
451
+ const summary = new ResultSummary ( args [ 0 ] , args [ 1 ] , { } , 5.3 )
452
+ return {
453
+ async * [ Symbol . asyncIterator ] ( ) {
454
+ return summary
455
+ } ,
456
+ async summary ( ) {
457
+ return summary
458
+ }
459
+ }
460
+ }
461
+ }
462
+ const session = new RxSession ( { session : _session } )
463
+ const query = 'the query'
464
+ const params = { }
465
+ const txConfig = { timeout : 1000 }
466
+
467
+ session . run ( query , params , txConfig ) . records ( ) . subscribe ( )
468
+
469
+ expect ( capture ) . toEqual ( [ [ query , params , txConfig ] ] )
470
+ } )
471
+ } )
472
+
473
+ describe ( '._beginTransaction()' , ( ) => {
474
+ it ( 'should round up sub milliseconds transaction timeouts' , ( ) => {
475
+ const capture = [ ]
476
+ const _session = {
477
+ _beginTransaction : async ( ...args ) => {
478
+ capture . push ( args )
479
+ return { }
480
+ }
481
+ }
482
+
483
+ const session = new RxSession ( {
484
+ session : _session
485
+ } )
486
+
487
+ const accessMode = 'READ'
488
+ const timeout = 0.2
489
+
490
+ session . _beginTransaction ( accessMode , { timeout } )
491
+ . subscribe ( )
492
+
493
+ expect ( capture [ 0 ] [ 1 ] . timeout ) . toEqual ( int ( 1 ) )
494
+ } )
495
+
496
+ it ( 'should log a warning for timeout configurations with sub milliseconds' , ( ) => {
497
+ const capture = [ ]
498
+ const loggerFunction = ( ...args ) => capture . push ( args )
499
+ const log = new logger . Logger ( 'debug' , loggerFunction )
500
+
501
+ const _session = {
502
+ _beginTransaction : async ( ...args ) => {
503
+ return { }
504
+ }
505
+ }
506
+
507
+ const session = new RxSession ( {
508
+ session : _session ,
509
+ log
510
+ } )
511
+
512
+ const accessMode = 'READ'
513
+ const timeout = 0.2
514
+
515
+ session . _beginTransaction ( accessMode , { timeout } )
516
+ . subscribe ( )
517
+
518
+ expect ( capture [ 0 ] ) . toEqual ( [
519
+ 'info' ,
520
+ `Transaction timeout expected to be an integer, got: ${ timeout } . The value will be round up.`
521
+ ] )
522
+ } )
523
+
524
+ it ( 'should not log a warning for timeout configurations without sub milliseconds' , ( ) => {
525
+ const capture = [ ]
526
+ const loggerFunction = ( ...args ) => capture . push ( args )
527
+ const log = new logger . Logger ( 'debug' , loggerFunction )
528
+
529
+ const _session = {
530
+ _beginTransaction : async ( ...args ) => {
531
+ return { }
532
+ }
533
+ }
534
+
535
+ const session = new RxSession ( {
536
+ session : _session ,
537
+ log
538
+ } )
539
+
540
+ const accessMode = 'READ'
541
+ const timeout = 1
542
+
543
+ session . _beginTransaction ( accessMode , { timeout } )
544
+ . subscribe ( )
545
+
546
+ expect ( capture . length ) . toEqual ( 0 )
547
+ } )
548
+ } )
549
+
445
550
function newSession ( lastBookmarks = bookmarks . Bookmarks . empty ( ) ) {
446
551
const connectionProvider = new ConnectionProvider ( )
447
552
connectionProvider . acquireConnection = ( ) => Promise . resolve ( null )
0 commit comments