Skip to content

Commit

Permalink
Adjust timeout exception type in QueryJob.result()
Browse files Browse the repository at this point in the history
  • Loading branch information
plamut committed Dec 11, 2019
1 parent 6e187d7 commit 2044a84
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

from __future__ import division

import concurrent.futures
import copy
import re
import threading

import requests
import six
from six.moves import http_client

Expand Down Expand Up @@ -3155,6 +3157,8 @@ def result(
exc.message += self._format_for_exception(self.query, self.job_id)
exc.query_job = self
raise
except requests.exceptions.Timeout as exc:
six.raise_from(concurrent.futures.TimeoutError, exc)

# If the query job is complete but there are no query results, this was
# special job, such as a DDL query. Return an empty result set to
Expand Down
22 changes: 22 additions & 0 deletions bigquery/tests/unit/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import concurrent
import copy
import json
import textwrap
import unittest

import mock
import pytest
import requests
from six.moves import http_client

try:
Expand Down Expand Up @@ -4604,6 +4606,26 @@ def test_result_error(self):
expected_line = "{}:{}".format(i, line)
assert expected_line in full_text

def test_result_transport_timeout_error(self):
query = textwrap.dedent(
"""
SELECT foo, bar
FROM table_baz
WHERE foo == bar"""
)

client = _make_client(project=self.PROJECT)
job = self._make_one(self.JOB_ID, query, client)
call_api_patch = mock.patch(
"google.cloud.bigquery.client.Client._call_api",
autospec=True,
side_effect=requests.exceptions.Timeout("Server response took too long."),
)

# Make sure that timeout errors get rebranded to concurrent futures timeout.
with call_api_patch, self.assertRaises(concurrent.futures.TimeoutError):
job.result(timeout=1)

def test__begin_error(self):
from google.cloud import exceptions

Expand Down

0 comments on commit 2044a84

Please sign in to comment.