@@ -8,16 +8,16 @@ import {
88 reloadTestingDatabases ,
99} from "../../../../utils/test-utils"
1010
11- describe ( "mysql driver > enableQueryTimeout connection option " , ( ) => {
11+ describe ( "driver > mysql > connection options > enableQueryTimeout " , ( ) => {
1212 let dataSources : DataSource [ ]
1313 const commonConnectionOptions : TestingOptions = {
1414 entities : [ __dirname + "/entity/*{.js,.ts}" ] ,
1515 schemaCreate : true ,
1616 dropSchema : true ,
1717 enabledDrivers : [ "mysql" ] ,
1818 }
19- const timeoutMs = 10
20- const longQueryTimeSec = 0.02
19+ const timeoutMs = 500
20+ const longQueryTimeSec = 1
2121 const shortQueryTimeSec = 0.005
2222
2323 describe ( "when enableQueryTimeout is true" , ( ) => {
@@ -37,13 +37,10 @@ describe("mysql driver > enableQueryTimeout connection option", () => {
3737 it ( "should throw a query execution timeout error for the query when it exceeds the maxQueryExecutionTime" , async ( ) => {
3838 await Promise . all (
3939 dataSources . map ( async ( dataSource ) => {
40- let errorThrown = false
41- try {
42- await dataSource . manager . query (
43- `SELECT SLEEP(${ longQueryTimeSec } )` ,
44- )
45- } catch ( err ) {
46- errorThrown = true
40+ await expect (
41+ dataSource . manager
42+ . sql `SELECT SLEEP(${ longQueryTimeSec } )` ,
43+ ) . to . be . rejected . then ( ( err ) => {
4744 expect ( err ) . to . have . nested . property (
4845 "driverError.code" ,
4946 "PROTOCOL_SEQUENCE_TIMEOUT" ,
@@ -52,24 +49,18 @@ describe("mysql driver > enableQueryTimeout connection option", () => {
5249 "driverError.timeout" ,
5350 timeoutMs ,
5451 )
55- }
56- expect ( errorThrown ) . to . be . true
52+ } )
5753 } ) ,
5854 )
5955 } )
6056
6157 it ( "should not throw a query execution timeout error for the query when it runs within the maxQueryExecutionTime" , async ( ) => {
6258 await Promise . all (
6359 dataSources . map ( async ( dataSource ) => {
64- let errorThrown = false
65- try {
66- await dataSource . manager . query (
67- `SELECT SLEEP(${ shortQueryTimeSec } )` ,
68- )
69- } catch ( err ) {
70- errorThrown = true
71- }
72- expect ( errorThrown ) . to . be . false
60+ await expect (
61+ dataSource . manager
62+ . sql `SELECT SLEEP(${ shortQueryTimeSec } )` ,
63+ ) . to . be . eventually . fulfilled
7364 } ) ,
7465 )
7566 } )
@@ -90,15 +81,10 @@ describe("mysql driver > enableQueryTimeout connection option", () => {
9081 it ( "should not throw a query execution timeout error" , ( ) => {
9182 Promise . all (
9283 datasources . map ( async ( dataSource ) => {
93- let errorThrown = false
94- try {
95- await dataSource . manager . query (
96- `SELECT SLEEP(${ longQueryTimeSec } )` ,
97- )
98- } catch ( err ) {
99- errorThrown = true
100- }
101- expect ( errorThrown ) . to . be . false
84+ await expect (
85+ dataSource . manager
86+ . sql `SELECT SLEEP(${ longQueryTimeSec } )` ,
87+ ) . to . eventually . be . fulfilled
10288 } ) ,
10389 )
10490 } )
0 commit comments