Skip to content

Commit

Permalink
mock out channel creation
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Nov 6, 2024
1 parent 89c660c commit 0ebee47
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions tests/unit/data/_async/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,13 @@ async def test__manage_channel_sleeps(
]
try:
client = self._make_one(project="project-id")
if refresh_interval is not None:
await client._manage_channel(
refresh_interval, refresh_interval
)
else:
await client._manage_channel()
with mock.patch.object(client.transport, "create_channel"):
if refresh_interval is not None:
await client._manage_channel(
refresh_interval, refresh_interval
)
else:
await client._manage_channel()
except asyncio.CancelledError:
pass
assert sleep.call_count == num_cycles
Expand All @@ -417,19 +418,20 @@ async def test__manage_channel_random(self):
uniform.side_effect = None
uniform.reset_mock()
sleep.reset_mock()
min_val = 200
max_val = 205
uniform.side_effect = lambda min_, max_: min_
sleep.side_effect = [None, asyncio.CancelledError]
try:
await client._manage_channel(min_val, max_val)
except asyncio.CancelledError:
pass
assert uniform.call_count == 2
uniform_args = [call[0] for call in uniform.call_args_list]
for found_min, found_max in uniform_args:
assert found_min == min_val
assert found_max == max_val
with mock.patch.object(client.transport, "create_channel"):
min_val = 200
max_val = 205
uniform.side_effect = lambda min_, max_: min_
sleep.side_effect = [None, asyncio.CancelledError]
try:
await client._manage_channel(min_val, max_val)
except asyncio.CancelledError:
pass
assert uniform.call_count == 2
uniform_args = [call[0] for call in uniform.call_args_list]
for found_min, found_max in uniform_args:
assert found_min == min_val
assert found_max == max_val

@pytest.mark.asyncio
@pytest.mark.parametrize("num_cycles", [0, 1, 10, 100])
Expand Down

0 comments on commit 0ebee47

Please sign in to comment.