|
20 | 20 |
|
21 | 21 | from google.api_core import exceptions |
22 | 22 | from google.api_core import retry_async |
| 23 | +from google.api_core import retry |
23 | 24 |
|
24 | 25 |
|
25 | 26 | @mock.patch("asyncio.sleep", autospec=True) |
@@ -95,6 +96,24 @@ async def test_retry_target_non_retryable_error(utcnow, sleep): |
95 | 96 | assert exc_info.value == exception |
96 | 97 | sleep.assert_not_called() |
97 | 98 |
|
| 99 | +@mock.patch("asyncio.sleep", autospec=True) |
| 100 | +@mock.patch( |
| 101 | + "google.api_core.datetime_helpers.utcnow", |
| 102 | + return_value=datetime.datetime.min, |
| 103 | + autospec=True, |
| 104 | +) |
| 105 | +@pytest.mark.asyncio |
| 106 | +async def test_retry_target_warning_for_retry(utcnow, sleep): |
| 107 | + predicate = retry_async.if_exception_type(ValueError) |
| 108 | + target = mock.AsyncMock(spec=["__call__"]) |
| 109 | + |
| 110 | + with pytest.raises(exceptions.GoogleAPICallError) as exc_info: |
| 111 | + retry.retry_target(target, predicate, range(10), None) |
| 112 | + |
| 113 | + assert exc_info.match("Warning: Using the synchronous google.api_core.retry.Retry with asynchronous calls may lead to unexpected results. Please use google.api_core.retry_async.AsyncRetry instead.") |
| 114 | + assert exc_info.type == exceptions.GoogleAPICallError |
| 115 | + sleep.assert_not_called() |
| 116 | + |
98 | 117 |
|
99 | 118 | @mock.patch("asyncio.sleep", autospec=True) |
100 | 119 | @mock.patch("google.api_core.datetime_helpers.utcnow", autospec=True) |
|
0 commit comments