Skip to content

Commit 23a42ea

Browse files
committed
tests: add more tests for lro
1 parent 0ebaf4b commit 23a42ea

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

tests/system/test_lro.py

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
from datetime import datetime, timedelta, timezone
1818

1919
from google import showcase
20+
from google.api_core import exceptions
21+
from google.rpc import code_pb2
2022

2123

22-
def test_lro(echo):
24+
def test_lro_success(echo):
2325
future = echo.wait(
2426
{
2527
"end_time": datetime.now(tz=timezone.utc) + timedelta(seconds=1),
@@ -33,10 +35,40 @@ def test_lro(echo):
3335
assert response.content.endswith("the snails...eventually.")
3436

3537

38+
def test_lro_error(echo):
39+
with pytest.raises(
40+
exceptions.GoogleAPICallError,
41+
match="(?i)This took longer than you said it should",
42+
):
43+
future = echo.wait(
44+
{
45+
"end_time": datetime.now(tz=timezone.utc) + timedelta(seconds=1),
46+
"error": {
47+
"code": code_pb2.Code.Value("DEADLINE_EXCEEDED"),
48+
"message": "This took longer than you said it should.",
49+
},
50+
}
51+
)
52+
future.result()
53+
54+
55+
def test_lro_no_result(echo):
56+
# As per the link below, `Some services might not provide a result`.
57+
# Neither `error`` or `response`.`
58+
# See https://github.com/googleapis/googleapis/blob/a6c9ed2d33105cb3dc9a0867a0a5d761b049b932/google/longrunning/operations.proto#L141
59+
future = echo.wait(
60+
{
61+
"end_time": datetime.now(tz=timezone.utc) + timedelta(seconds=1),
62+
}
63+
)
64+
response = future.result()
65+
assert response is None
66+
67+
3668
if os.environ.get("GAPIC_PYTHON_ASYNC", "true") == "true":
3769

3870
@pytest.mark.asyncio
39-
async def test_lro_async(async_echo):
71+
async def test_lro_async_success(async_echo):
4072

4173
future = await async_echo.wait(
4274
{
@@ -49,3 +81,34 @@ async def test_lro_async(async_echo):
4981
response = await future.result()
5082
assert isinstance(response, showcase.WaitResponse)
5183
assert response.content.endswith("the snails...eventually.")
84+
85+
@pytest.mark.asyncio
86+
async def test_lro_async_error(async_echo):
87+
88+
with pytest.raises(
89+
exceptions.GoogleAPICallError,
90+
match="(?i)This took longer than you said it should",
91+
):
92+
future = await async_echo.wait(
93+
{
94+
"end_time": datetime.now(tz=timezone.utc) + timedelta(seconds=1),
95+
"error": {
96+
"code": code_pb2.Code.Value("DEADLINE_EXCEEDED"),
97+
"message": "This took longer than you said it should.",
98+
},
99+
}
100+
)
101+
await future.result(timeout=600)
102+
103+
@pytest.mark.asyncio
104+
async def test_lro_async_no_result(async_echo):
105+
# As per the link below, `Some services might not provide a result`.
106+
# Neither `error`` or `response`.`
107+
# See https://github.com/googleapis/googleapis/blob/a6c9ed2d33105cb3dc9a0867a0a5d761b049b932/google/longrunning/operations.proto#L141
108+
future = await async_echo.wait(
109+
{
110+
"end_time": datetime.now(tz=timezone.utc) + timedelta(seconds=1),
111+
}
112+
)
113+
response = await future.result()
114+
assert response is None

0 commit comments

Comments
 (0)