@@ -29,40 +29,40 @@ def test_insert_rows_json_ssl_error_no_retry(bigquery_client, dataset_id, projec
2929 schema = [bigquery .SchemaField ("name" , "STRING" )]
3030 table = bigquery .Table (table_id , schema = schema )
3131 bigquery_client .create_table (table )
32-
33- # We mock the api_request to simulate the GFE abruptly closing the connection
34- # which manifests as a requests.exceptions.SSLError.
35- original_api_request = bigquery_client ._connection .api_request
36- call_count = 0
32+ try :
33+ # We mock the api_request to simulate the GFE abruptly closing the connection
34+ # which manifests as a requests.exceptions.SSLError.
35+ original_api_request = bigquery_client ._connection .api_request
36+ call_count = 0
3737
38- def mock_api_request (* args , ** kwargs ):
39- nonlocal call_count
40- call_count += 1
41- raise requests .exceptions .SSLError ("EOF occurred in violation of protocol" )
38+ def mock_api_request (* args , ** kwargs ):
39+ nonlocal call_count
40+ call_count += 1
41+ raise requests .exceptions .SSLError ("EOF occurred in violation of protocol" )
4242
43- with mock .patch .object (bigquery_client ._connection , "api_request" , side_effect = mock_api_request ):
44- # Use a reasonably short deadline for the test, although it should fail on the first attempt anyway.
45- retry = bigquery .DEFAULT_RETRY .with_deadline (5.0 )
46-
47- start_time = time .time ()
48- with pytest .raises (requests .exceptions .SSLError ) as excinfo :
49- bigquery_client .insert_rows_json (
50- table ,
51- [{"name" : "test" }],
52- retry = retry
53- )
54- duration = time .time () - start_time
43+ with mock .patch .object (bigquery_client ._connection , "api_request" , side_effect = mock_api_request ):
44+ # Use a reasonably short deadline for the test, although it should fail on the first attempt anyway.
45+ retry = bigquery .DEFAULT_RETRY .with_deadline (5.0 )
5546
56- # Verification:
57- # 1. It should NOT have retried (total calls should be 1)
58- assert call_count == 1
59-
60- # 2. It should have failed quickly (much less than the 5s deadline)
61- assert duration < 2.0
62-
63- # 3. The error message should contain our descriptive wrapping
64- assert "invalid table schema" in str (excinfo .value )
65- assert "SSL/Connection error occurred" in str (excinfo .value )
47+ start_time = time .time ()
48+ with pytest .raises (requests .exceptions .SSLError ) as excinfo :
49+ bigquery_client .insert_rows_json (
50+ table ,
51+ [{"name" : "test" }],
52+ retry = retry
53+ )
54+ duration = time .time () - start_time
6655
67- # Cleanup
68- bigquery_client .delete_table (table_id )
56+ # Verification:
57+ # 1. It should NOT have retried (total calls should be 1)
58+ assert call_count == 1
59+
60+ # 2. It should have failed quickly (much less than the 5s deadline)
61+ assert duration < 2.0
62+
63+ # 3. The error message should contain our descriptive wrapping
64+ assert "invalid table schema" in str (excinfo .value )
65+ assert "SSL/Connection error occurred" in str (excinfo .value )
66+ finally :
67+ # Cleanup
68+ bigquery_client .delete_table (table_id )
0 commit comments