|
6 | 6 | from ssl import CERT_NONE, CERT_REQUIRED
|
7 | 7 |
|
8 | 8 | import pyarrow
|
| 9 | +import urllib3 |
9 | 10 |
|
10 | 11 | import databricks.sql
|
11 | 12 | from databricks.sql.thrift_api.TCLIService import ttypes
|
@@ -1033,7 +1034,7 @@ def test_handle_execute_response_sets_active_op_handle(self):
|
1033 | 1034 |
|
1034 | 1035 | self.assertEqual(mock_resp.operationHandle, mock_cursor.active_op_handle)
|
1035 | 1036 |
|
1036 |
| - @patch("thrift.transport.THttpClient.THttpClient") |
| 1037 | + @patch("databricks.sql.auth.thrift_http_client.THttpClient") |
1037 | 1038 | @patch("databricks.sql.thrift_api.TCLIService.TCLIService.Client.GetOperationStatus")
|
1038 | 1039 | @patch("databricks.sql.thrift_backend._retry_policy", new_callable=retry_policy_factory)
|
1039 | 1040 | def test_make_request_will_retry_GetOperationStatus(
|
@@ -1089,6 +1090,51 @@ def test_make_request_will_retry_GetOperationStatus(
|
1089 | 1090 | # The warnings should include this text
|
1090 | 1091 | self.assertIn(f"{this_gos_name} failed with code {errno.EEXIST} and will attempt to retry", cm.output[0])
|
1091 | 1092 |
|
| 1093 | + @patch("databricks.sql.thrift_api.TCLIService.TCLIService.Client.GetOperationStatus") |
| 1094 | + @patch("databricks.sql.thrift_backend._retry_policy", new_callable=retry_policy_factory) |
| 1095 | + def test_make_request_will_retry_GetOperationStatus_for_http_error( |
| 1096 | + self, mock_retry_policy, mock_gos): |
| 1097 | + |
| 1098 | + import urllib3.exceptions |
| 1099 | + mock_gos.side_effect = urllib3.exceptions.HTTPError("Read timed out") |
| 1100 | + |
| 1101 | + import thrift, errno |
| 1102 | + from databricks.sql.thrift_api.TCLIService.TCLIService import Client |
| 1103 | + from databricks.sql.exc import RequestError |
| 1104 | + from databricks.sql.utils import NoRetryReason |
| 1105 | + from databricks.sql.auth.thrift_http_client import THttpClient |
| 1106 | + |
| 1107 | + this_gos_name = "GetOperationStatus" |
| 1108 | + mock_gos.__name__ = this_gos_name |
| 1109 | + |
| 1110 | + protocol = thrift.protocol.TBinaryProtocol.TBinaryProtocol(THttpClient) |
| 1111 | + client = Client(protocol) |
| 1112 | + |
| 1113 | + req = ttypes.TGetOperationStatusReq( |
| 1114 | + operationHandle=self.operation_handle, |
| 1115 | + getProgressUpdate=False, |
| 1116 | + ) |
| 1117 | + |
| 1118 | + EXPECTED_RETRIES = 2 |
| 1119 | + |
| 1120 | + thrift_backend = ThriftBackend( |
| 1121 | + "foobar", |
| 1122 | + 443, |
| 1123 | + "path", [], |
| 1124 | + auth_provider=AuthProvider(), |
| 1125 | + _retry_stop_after_attempts_count=EXPECTED_RETRIES, |
| 1126 | + _retry_delay_default=1) |
| 1127 | + |
| 1128 | + |
| 1129 | + with self.assertRaises(RequestError) as cm: |
| 1130 | + thrift_backend.make_request(client.GetOperationStatus, req) |
| 1131 | + |
| 1132 | + |
| 1133 | + self.assertEqual(NoRetryReason.OUT_OF_ATTEMPTS.value, cm.exception.context["no-retry-reason"]) |
| 1134 | + self.assertEqual(f'{EXPECTED_RETRIES}/{EXPECTED_RETRIES}', cm.exception.context["attempt"]) |
| 1135 | + |
| 1136 | + |
| 1137 | + |
1092 | 1138 |
|
1093 | 1139 | @patch("thrift.transport.THttpClient.THttpClient")
|
1094 | 1140 | def test_make_request_wont_retry_if_headers_not_present(self, t_transport_class):
|
|
0 commit comments