14
14
from datetime import date , datetime , timezone
15
15
from typing import TYPE_CHECKING , NamedTuple
16
16
from unittest import mock
17
+ from unittest .mock import MagicMock
17
18
18
19
import pytest
19
20
import pytz
@@ -826,6 +827,7 @@ def test_invalid_bind_data_type(conn_cnx):
826
827
cnx .cursor ().execute ("select 1 from dual where 1=%s" , ([1 , 2 , 3 ],))
827
828
828
829
830
+ @pytest .mark .skipolddriver
829
831
def test_timeout_query (conn_cnx ):
830
832
with conn_cnx () as cnx :
831
833
with cnx .cursor () as c :
@@ -836,10 +838,30 @@ def test_timeout_query(conn_cnx):
836
838
)
837
839
assert err .value .errno == 604 , (
838
840
"Invalid error code"
839
- and "SQL execution was cancelled by the client due to a timeout"
841
+ and "SQL execution was cancelled by the client due to a timeout. Error message received from the server: SQL execution canceled "
840
842
in err .value .msg
841
843
)
842
844
845
+ with pytest .raises (errors .ProgrammingError ) as err :
846
+ # we can not precisely control the timing to send cancel query request right after server
847
+ # executes the query but before returning the results back to client
848
+ # it depends on python scheduling and server processing speed, so we mock here
849
+ with mock .patch .object (
850
+ c , "_timebomb" , new_callable = MagicMock
851
+ ) as mock_timerbomb :
852
+ mock_timerbomb .executed = True
853
+ c .execute (
854
+ "select 123'" ,
855
+ timeout = 0.1 ,
856
+ )
857
+ assert c ._timebomb .executed is True and err .value .errno == 1003 , (
858
+ "Invalid error code"
859
+ and "SQL compilation error:\n syntax error line 1 at position 10 unexpected '''."
860
+ in err .value .msg
861
+ and "SQL execution was cancelled by the client due to a timeout"
862
+ not in err .value .msg
863
+ )
864
+
843
865
844
866
def test_executemany (conn , db_parameters ):
845
867
"""Executes many statements. Client binding is supported by either dict, or list data types.
0 commit comments