Skip to content

Commit e111909

Browse files
committed
test fixes
Signed-off-by: Sai Shree Pradhan <saishree.pradhan@databricks.com>
1 parent 804f9e0 commit e111909

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/databricks/sql/telemetry/latency_logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def _safe_call(func_to_call):
253253
statement_type=statement_type,
254254
is_compressed=_safe_call(extractor.get_is_compressed),
255255
execution_result=_safe_call(extractor.get_execution_result),
256-
retry_count=extractor.get_retry_count(),
256+
retry_count=_safe_call(extractor.get_retry_count),
257257
chunk_id=_safe_call(extractor.get_chunk_id),
258258
)
259259

tests/unit/test_downloader.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_run_link_expired(self, mock_time):
2727
# Already expired
2828
result_link.expiryTime = 999
2929
d = downloader.ResultSetDownloadHandler(
30-
settings, result_link, ssl_options=SSLOptions()
30+
settings, result_link, ssl_options=SSLOptions(), chunk_id=0
3131
)
3232

3333
with self.assertRaises(Error) as context:
@@ -43,7 +43,7 @@ def test_run_link_past_expiry_buffer(self, mock_time):
4343
# Within the expiry buffer time
4444
result_link.expiryTime = 1004
4545
d = downloader.ResultSetDownloadHandler(
46-
settings, result_link, ssl_options=SSLOptions()
46+
settings, result_link, ssl_options=SSLOptions(), chunk_id=0
4747
)
4848

4949
with self.assertRaises(Error) as context:
@@ -63,7 +63,7 @@ def test_run_get_response_not_ok(self, mock_time, mock_session):
6363
result_link = Mock(expiryTime=1001)
6464

6565
d = downloader.ResultSetDownloadHandler(
66-
settings, result_link, ssl_options=SSLOptions()
66+
settings, result_link, ssl_options=SSLOptions(), chunk_id=0
6767
)
6868
with self.assertRaises(requests.exceptions.HTTPError) as context:
6969
d.run()
@@ -82,7 +82,7 @@ def test_run_uncompressed_successful(self, mock_time, mock_session):
8282
result_link = Mock(bytesNum=100, expiryTime=1001)
8383

8484
d = downloader.ResultSetDownloadHandler(
85-
settings, result_link, ssl_options=SSLOptions()
85+
settings, result_link, ssl_options=SSLOptions(), chunk_id=0
8686
)
8787
file = d.run()
8888

@@ -105,7 +105,7 @@ def test_run_compressed_successful(self, mock_time, mock_session):
105105
result_link = Mock(bytesNum=100, expiryTime=1001)
106106

107107
d = downloader.ResultSetDownloadHandler(
108-
settings, result_link, ssl_options=SSLOptions()
108+
settings, result_link, ssl_options=SSLOptions(), chunk_id=0
109109
)
110110
file = d.run()
111111

@@ -121,7 +121,7 @@ def test_download_connection_error(self, mock_time, mock_session):
121121
mock_session.return_value.get.return_value.content = b'\x04"M\x18h@d\x00\x00\x00\x00\x00\x00\x00#\x14\x00\x00\x00\xaf1234567890\n\x00BP67890\x00\x00\x00\x00'
122122

123123
d = downloader.ResultSetDownloadHandler(
124-
settings, result_link, ssl_options=SSLOptions()
124+
settings, result_link, ssl_options=SSLOptions(), chunk_id=0
125125
)
126126
with self.assertRaises(ConnectionError):
127127
d.run()
@@ -136,7 +136,7 @@ def test_download_timeout(self, mock_time, mock_session):
136136
mock_session.return_value.get.return_value.content = b'\x04"M\x18h@d\x00\x00\x00\x00\x00\x00\x00#\x14\x00\x00\x00\xaf1234567890\n\x00BP67890\x00\x00\x00\x00'
137137

138138
d = downloader.ResultSetDownloadHandler(
139-
settings, result_link, ssl_options=SSLOptions()
139+
settings, result_link, ssl_options=SSLOptions(), chunk_id=0
140140
)
141141
with self.assertRaises(TimeoutError):
142142
d.run()

tests/unit/test_thrift_backend.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def test_handle_execute_response_sets_compression_in_direct_results(
649649
ssl_options=SSLOptions(),
650650
)
651651

652-
execute_response, _ = thrift_backend._handle_execute_response(
652+
execute_response, _, _ = thrift_backend._handle_execute_response(
653653
t_execute_resp, Mock()
654654
)
655655
self.assertEqual(execute_response.lz4_compressed, lz4Compressed)
@@ -892,6 +892,7 @@ def test_handle_execute_response_can_handle_without_direct_results(
892892
(
893893
execute_response,
894894
_,
895+
_,
895896
) = thrift_backend._handle_execute_response(execute_resp, Mock())
896897
self.assertEqual(
897898
execute_response.status,
@@ -927,7 +928,7 @@ def test_handle_execute_response_can_handle_with_direct_results(self):
927928
auth_provider=AuthProvider(),
928929
ssl_options=SSLOptions(),
929930
)
930-
thrift_backend._results_message_to_execute_response = Mock()
931+
thrift_backend._results_message_to_execute_response = Mock(return_value=(Mock(), Mock()))
931932

932933
thrift_backend._handle_execute_response(execute_resp, Mock())
933934

@@ -965,7 +966,7 @@ def test_use_arrow_schema_if_available(self, tcli_service_class):
965966
)
966967
)
967968
thrift_backend = self._make_fake_thrift_backend()
968-
execute_response, _ = thrift_backend._handle_execute_response(
969+
execute_response, _, _ = thrift_backend._handle_execute_response(
969970
t_execute_resp, Mock()
970971
)
971972

@@ -997,7 +998,7 @@ def test_fall_back_to_hive_schema_if_no_arrow_schema(self, tcli_service_class):
997998
)
998999
)
9991000
thrift_backend = self._make_fake_thrift_backend()
1000-
_, _ = thrift_backend._handle_execute_response(t_execute_resp, Mock())
1001+
_, _, _ = thrift_backend._handle_execute_response(t_execute_resp, Mock())
10011002

10021003
self.assertEqual(
10031004
hive_schema_mock,
@@ -1046,6 +1047,7 @@ def test_handle_execute_response_reads_has_more_rows_in_direct_results(
10461047
(
10471048
execute_response,
10481049
has_more_rows_result,
1050+
_
10491051
) = thrift_backend._handle_execute_response(execute_resp, Mock())
10501052

10511053
self.assertEqual(is_direct_results, has_more_rows_result)
@@ -1179,7 +1181,7 @@ def test_execute_statement_calls_client_and_handle_execute_response(
11791181
ssl_options=SSLOptions(),
11801182
)
11811183
thrift_backend._handle_execute_response = Mock()
1182-
thrift_backend._handle_execute_response.return_value = (Mock(), Mock())
1184+
thrift_backend._handle_execute_response.return_value = (Mock(), Mock(), Mock())
11831185
cursor_mock = Mock()
11841186

11851187
result = thrift_backend.execute_command(
@@ -1215,7 +1217,7 @@ def test_get_catalogs_calls_client_and_handle_execute_response(
12151217
ssl_options=SSLOptions(),
12161218
)
12171219
thrift_backend._handle_execute_response = Mock()
1218-
thrift_backend._handle_execute_response.return_value = (Mock(), Mock())
1220+
thrift_backend._handle_execute_response.return_value = (Mock(), Mock(), Mock())
12191221
cursor_mock = Mock()
12201222

12211223
result = thrift_backend.get_catalogs(Mock(), 100, 200, cursor_mock)
@@ -1248,7 +1250,7 @@ def test_get_schemas_calls_client_and_handle_execute_response(
12481250
ssl_options=SSLOptions(),
12491251
)
12501252
thrift_backend._handle_execute_response = Mock()
1251-
thrift_backend._handle_execute_response.return_value = (Mock(), Mock())
1253+
thrift_backend._handle_execute_response.return_value = (Mock(), Mock(), Mock())
12521254
cursor_mock = Mock()
12531255

12541256
result = thrift_backend.get_schemas(
@@ -1290,7 +1292,7 @@ def test_get_tables_calls_client_and_handle_execute_response(
12901292
ssl_options=SSLOptions(),
12911293
)
12921294
thrift_backend._handle_execute_response = Mock()
1293-
thrift_backend._handle_execute_response.return_value = (Mock(), Mock())
1295+
thrift_backend._handle_execute_response.return_value = (Mock(), Mock(), Mock())
12941296
cursor_mock = Mock()
12951297

12961298
result = thrift_backend.get_tables(
@@ -1336,7 +1338,7 @@ def test_get_columns_calls_client_and_handle_execute_response(
13361338
ssl_options=SSLOptions(),
13371339
)
13381340
thrift_backend._handle_execute_response = Mock()
1339-
thrift_backend._handle_execute_response.return_value = (Mock(), Mock())
1341+
thrift_backend._handle_execute_response.return_value = (Mock(), Mock(), Mock())
13401342
cursor_mock = Mock()
13411343

13421344
result = thrift_backend.get_columns(
@@ -1682,7 +1684,7 @@ def test_handle_execute_response_sets_active_op_handle(self):
16821684
thrift_backend = self._make_fake_thrift_backend()
16831685
thrift_backend._check_direct_results_for_error = Mock()
16841686
thrift_backend._wait_until_command_done = Mock()
1685-
thrift_backend._results_message_to_execute_response = Mock()
1687+
thrift_backend._results_message_to_execute_response = Mock(return_value=(Mock(), Mock()))
16861688

16871689
# Create a mock response with a real operation handle
16881690
mock_resp = Mock()
@@ -2254,6 +2256,7 @@ def test_execute_command_sets_complex_type_fields_correctly(
22542256
mock_handle_execute_response.return_value = (
22552257
mock_execute_response,
22562258
mock_arrow_schema,
2259+
Mock()
22572260
)
22582261

22592262
# Iterate through each possible combination of native types (True, False and unset)

0 commit comments

Comments
 (0)