-
Notifications
You must be signed in to change notification settings - Fork 110
Retry attempts that fail due to a connection timeout #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
fa13d75
b44d0b8
22d2ac0
44f12b7
09cefec
de96fce
21c06d4
befdf3d
fb1275b
c76ee65
7474834
fa1fd50
bf65b81
a0d340e
a55cf9d
38411a8
5096ef0
5c1ee79
1f87a38
baff3d5
10016ea
4db4ad0
767e34c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
import sys | ||
import threading | ||
import time | ||
from unittest import loader, skipIf, skipUnless, TestCase | ||
from unittest import loader, skipIf, skipUnless, TestCase, mock | ||
from uuid import uuid4 | ||
|
||
import numpy as np | ||
|
@@ -360,6 +360,42 @@ def execute_really_long_query(): | |
cursor.execute("SELECT * FROM range(3)") | ||
self.assertEqual(len(cursor.fetchall()), 3) | ||
|
||
def test_retry_after_connection_timeout(self): | ||
|
||
import socket | ||
from databricks.sql.thrift_api.TCLIService import ttypes | ||
|
||
ATTEMPTS_TO_TRY = 2 | ||
|
||
with self.cursor({}) as cursor: | ||
cursor.execute("SELECT id FROM RANGE(10)") | ||
op_handle = cursor.active_op_handle | ||
thrift_backend = cursor.thrift_backend | ||
|
||
|
||
thrift_backend._retry_stop_after_attempts_count = ATTEMPTS_TO_TRY | ||
req = ttypes.TGetOperationStatusReq( | ||
operationHandle=op_handle, | ||
getProgressUpdate=False, | ||
) | ||
|
||
|
||
with self.assertRaises(OperationalError) as cm: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be more specific to assert RequestError There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually removed the e2e tests for this behaviour because they were no more useful than unit tests. I'll add an e2e test for this scenario after we merge support for http proxies. Then we can simulate real timeouts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the unit tests asserts on |
||
with mock.patch("socket.create_connection") as mock_create_connection: | ||
mock_create_connection.side_effect = OSError("[Errno 110]: Connection timed out") | ||
thrift_backend.make_request(thrift_backend._client.GetOperationStatus, req) | ||
|
||
self.assertIn("{0}/{0}".format(ATTEMPTS_TO_TRY), cm.exception.message_with_context()) | ||
susodapop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
with self.assertRaises(OperationalError) as cm: | ||
with mock.patch("socket.create_connection") as mock_create_connection: | ||
mock_create_connection.side_effect = socket.timeout | ||
thrift_backend.make_request(thrift_backend._client.GetOperationStatus, req) | ||
|
||
self.assertIn("{0}/{0}".format(ATTEMPTS_TO_TRY), cm.exception.message_with_context()) | ||
|
||
|
||
|
||
@skipIf(pysql_has_version('<', '2'), 'requires pysql v2') | ||
def test_can_execute_command_after_failure(self): | ||
with self.cursor({}) as cursor: | ||
|
Uh oh!
There was an error while loading. Please reload this page.