16
16
* See the License for the specific language governing permissions and
17
17
* limitations under the License.
18
18
*/
19
- import { ConnectionProvider , Session , Connection , TransactionPromise , Transaction , BookmarkManager , bookmarkManager , NotificationFilter } from '../src'
19
+ import { ConnectionProvider , Session , Connection , TransactionPromise , Transaction , BookmarkManager , bookmarkManager , NotificationFilter , int } from '../src'
20
20
import { bookmarks } from '../src/internal'
21
21
import { ACCESS_MODE_READ , FETCH_ALL } from '../src/internal/constants'
22
22
import ManagedTransaction from '../src/transaction-managed'
23
23
import { AuthToken } from '../src/types'
24
24
import FakeConnection from './utils/connection.fake'
25
25
import { validNotificationFilters } from './utils/notification-filters.fixtures'
26
+ import fc from 'fast-check'
26
27
27
28
describe ( 'session' , ( ) => {
28
29
const systemBookmarks = [ 'sys:bm01' , 'sys:bm02' ]
@@ -474,6 +475,28 @@ describe('session', () => {
474
475
expect . objectContaining ( { auth } )
475
476
)
476
477
} )
478
+
479
+ it ( 'should round up sub milliseconds transaction timeouts' , async ( ) => {
480
+ return await fc . assert (
481
+ fc . asyncProperty (
482
+ fc . float ( { min : 0 , noNaN : true } ) ,
483
+ async ( timeout : number ) => {
484
+ const connection = mockBeginWithSuccess ( newFakeConnection ( ) )
485
+
486
+ const { session } = setupSession ( {
487
+ connection,
488
+ beginTx : false ,
489
+ database : 'neo4j'
490
+ } )
491
+
492
+ await session . beginTransaction ( { timeout } )
493
+
494
+ expect ( connection . seenBeginTransaction [ 0 ] [ 0 ] . txConfig . timeout )
495
+ . toEqual ( int ( Math . ceil ( timeout ) ) )
496
+ }
497
+ )
498
+ )
499
+ } )
477
500
} )
478
501
479
502
describe ( '.commit()' , ( ) => {
@@ -588,6 +611,29 @@ describe('session', () => {
588
611
expect ( status . functionCalled ) . toEqual ( true )
589
612
expect ( run ) . toHaveBeenCalledWith ( query , params )
590
613
} )
614
+
615
+ it ( 'should round up sub milliseconds transaction timeouts' , async ( ) => {
616
+ return await fc . assert (
617
+ fc . asyncProperty (
618
+ fc . float ( { min : 0 , noNaN : true } ) ,
619
+ async ( timeout : number ) => {
620
+ const connection = mockBeginWithSuccess ( newFakeConnection ( ) )
621
+ const session = newSessionWithConnection ( connection , false , FETCH_ALL )
622
+ // @ts -expect-error
623
+ jest . spyOn ( Transaction . prototype , 'run' ) . mockImplementation ( async ( ) => await Promise . resolve ( ) )
624
+ const query = 'RETURN $a'
625
+ const params = { a : 1 }
626
+
627
+ await execute ( session ) ( async ( tx : ManagedTransaction ) => {
628
+ await tx . run ( query , params )
629
+ } , { timeout } )
630
+
631
+ expect ( connection . seenBeginTransaction [ 0 ] [ 0 ] . txConfig . timeout )
632
+ . toEqual ( int ( Math . ceil ( timeout ) ) )
633
+ }
634
+ )
635
+ )
636
+ } )
591
637
} )
592
638
593
639
describe ( '.run()' , ( ) => {
@@ -893,7 +939,7 @@ describe('session', () => {
893
939
} )
894
940
895
941
await session . run ( 'query' )
896
-
942
+
897
943
expect ( connectionProvider . acquireConnection ) . toBeCalledWith (
898
944
expect . objectContaining ( { auth } )
899
945
)
@@ -918,6 +964,28 @@ describe('session', () => {
918
964
expect . objectContaining ( { auth } )
919
965
)
920
966
} )
967
+
968
+ it ( 'should round up sub milliseconds transaction timeouts' , async ( ) => {
969
+ return await fc . assert (
970
+ fc . asyncProperty (
971
+ fc . float ( { min : 0 , noNaN : true } ) ,
972
+ async ( timeout : number ) => {
973
+ const connection = newFakeConnection ( )
974
+
975
+ const { session } = setupSession ( {
976
+ connection,
977
+ beginTx : false ,
978
+ database : 'neo4j'
979
+ } )
980
+
981
+ await session . run ( 'query' , { } , { timeout } )
982
+
983
+ expect ( connection . seenProtocolOptions [ 0 ] . txConfig . timeout )
984
+ . toEqual ( int ( Math . ceil ( timeout ) ) )
985
+ }
986
+ )
987
+ )
988
+ } )
921
989
} )
922
990
} )
923
991
0 commit comments