@@ -474,6 +474,18 @@ def do_sent_request(op_input: OperationInput, options: Any) -> OperationOutput:
474474 )
475475 self .assertIsInstance (self .save_options .http_client , MockHttpClient )
476476
477+ # "operation_timeout"
478+ self .assertEqual (None , clinet ._client ._options .operation_timeout )
479+ clinet .invoke_operation (
480+ OperationInput (
481+ op_name = 'InvokeOperation' ,
482+ method = 'GET' ,
483+ bucket = 'bucket' ,
484+ ),
485+ operation_timeout = 40 ,
486+ )
487+ self .assertEqual (40 , self .save_options .operation_timeout )
488+
477489
478490 def test_invoke_operation_user_agent (self ):
479491 self .save_op_context : SigningContext = None
@@ -1162,6 +1174,121 @@ def _do_sent(request: HttpRequest, **kwargs) -> HttpResponse:
11621174 for d in self .save_data :
11631175 self .assertEqual (data , d )
11641176
1177+ def test_invoke_operation_retryable_with_operation_timeout (self ):
1178+ self .save_request : List [HttpRequest ] = None
1179+ self .save_data : List [Any ] = None
1180+
1181+ def _do_sent (request : HttpRequest , ** kwargs ) -> HttpResponse :
1182+ self .save_request .append (request )
1183+ self .save_data .append (_read_body (request .body ))
1184+ self .assertIsInstance (request .body , io_utils .TeeIterator )
1185+ raise exceptions .ServiceError (
1186+ status_code = 500 ,
1187+ code = 'InternalError' ,
1188+ request_id = 'id-1234' ,
1189+ message = 'Please contact the server administrator, oss@service.aliyun.com.' ,
1190+ ec = '' ,
1191+ timestamp = '' ,
1192+ request_target = ''
1193+ )
1194+
1195+ cfg = config .Config (
1196+ region = 'cn-hangzhou' ,
1197+ credentials_provider = credentials .AnonymousCredentialsProvider (),
1198+ )
1199+ clinet = client .Client (cfg )
1200+
1201+
1202+ # str, no operation_timeout
1203+ self .save_request = []
1204+ self .save_data = []
1205+ data = 'hello world'
1206+
1207+ with mock .patch .object (clinet ._client ._options .http_client , 'send' , new = _do_sent ) as _ :
1208+ try :
1209+ clinet .put_object (models .PutObjectRequest (
1210+ bucket = 'bucket' ,
1211+ key = 'key' ,
1212+ body = data
1213+ ))
1214+ self .fail ('should not here' )
1215+ except exceptions .OperationError as err :
1216+ self .assertIn ("InternalError" , str (err ))
1217+
1218+ self .assertEqual (3 , len (self .save_request ))
1219+ self .assertEqual (3 , len (self .save_data ))
1220+ for d in self .save_data :
1221+ self .assertEqual (data .encode (), d )
1222+
1223+ # str, with 0 operation_timeout
1224+ self .save_request = []
1225+ self .save_data = []
1226+ data = 'hello world'
1227+
1228+ with mock .patch .object (clinet ._client ._options .http_client , 'send' , new = _do_sent ) as _ :
1229+ try :
1230+ clinet .put_object (models .PutObjectRequest (
1231+ bucket = 'bucket' ,
1232+ key = 'key' ,
1233+ body = data
1234+ ), operation_timeout = 0 )
1235+ self .fail ('should not here' )
1236+ except exceptions .OperationError as err :
1237+ self .assertIn ("InternalError" , str (err ))
1238+
1239+ self .assertEqual (1 , len (self .save_request ))
1240+ self .assertEqual (1 , len (self .save_data ))
1241+ for d in self .save_data :
1242+ self .assertEqual (data .encode (), d )
1243+
1244+ # str, with 10s operation_timeout
1245+ self .save_request = []
1246+ self .save_data = []
1247+ data = 'hello world'
1248+
1249+ with mock .patch .object (clinet ._client ._options .http_client , 'send' , new = _do_sent ) as _ :
1250+ try :
1251+ clinet .put_object (models .PutObjectRequest (
1252+ bucket = 'bucket' ,
1253+ key = 'key' ,
1254+ body = data
1255+ ), operation_timeout = 10 )
1256+ self .fail ('should not here' )
1257+ except exceptions .OperationError as err :
1258+ self .assertIn ("InternalError" , str (err ))
1259+
1260+ self .assertEqual (3 , len (self .save_request ))
1261+ self .assertEqual (3 , len (self .save_data ))
1262+ for d in self .save_data :
1263+ self .assertEqual (data .encode (), d )
1264+
1265+ # str, with 4s operation_timeout 2
1266+ cfg = config .Config (
1267+ region = 'cn-hangzhou' ,
1268+ credentials_provider = credentials .AnonymousCredentialsProvider (),
1269+ retryer = retry .StandardRetryer (backoff_delayer = retry .FixedDelayBackoff (2.5 ))
1270+ )
1271+ clinet = client .Client (cfg )
1272+ self .save_request = []
1273+ self .save_data = []
1274+ data = 'hello world'
1275+
1276+ with mock .patch .object (clinet ._client ._options .http_client , 'send' , new = _do_sent ) as _ :
1277+ try :
1278+ clinet .put_object (models .PutObjectRequest (
1279+ bucket = 'bucket' ,
1280+ key = 'key' ,
1281+ body = data
1282+ ), operation_timeout = 4 )
1283+ self .fail ('should not here' )
1284+ except exceptions .OperationError as err :
1285+ self .assertIn ("InternalError" , str (err ))
1286+
1287+ self .assertEqual (2 , len (self .save_request ))
1288+ self .assertEqual (2 , len (self .save_data ))
1289+ for d in self .save_data :
1290+ self .assertEqual (data .encode (), d )
1291+
11651292 def test_invoke_operation_addressing_mode (self ):
11661293 """ """
11671294 self .save_op_context : SigningContext = None
0 commit comments