Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 045900a

Browse files
committed
combined channel refresh tests
1 parent b3e110f commit 045900a

2 files changed

Lines changed: 33 additions & 81 deletions

File tree

tests/system/data/test_system_async.py

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -266,75 +266,49 @@ async def test_ping_and_warm(self, client, target):
266266
@CrossSync.pytest
267267
async def test_channel_refresh(self, table_id, instance_id, temp_rows):
268268
"""
269-
change grpc channel to refresh quickly, then schedule a read_rows call after refresh
270-
to ensure new channel is in place and works
271-
"""
272-
await temp_rows.add_row(b"row_key_1")
273-
await temp_rows.add_row(b"row_key_2")
274-
async with self._make_client() as client:
275-
# start custom refresh task
276-
client._channel_refresh_task.cancel()
277-
client._channel_refresh_task = CrossSync.create_task(
278-
client._manage_channel,
279-
refresh_interval_min=0.25,
280-
refresh_interval_max=0.25,
281-
sync_executor=client._executor,
282-
)
283-
# let task run
284-
await CrossSync.yield_to_event_loop()
285-
async with client.get_table(instance_id, table_id) as table:
286-
rows = await table.read_rows({})
287-
channel_wrapper = client.transport.grpc_channel
288-
first_channel = channel_wrapper._channel
289-
assert len(rows) == 2
290-
await CrossSync.sleep(0.5)
291-
rows_after_refresh = await table.read_rows({})
292-
assert len(rows_after_refresh) == 2
293-
assert client.transport.grpc_channel is channel_wrapper
294-
updated_channel = channel_wrapper._channel
295-
assert updated_channel is not first_channel
296-
# ensure interceptors are kept (gapic's logging interceptor, and metric interceptor)
297-
if CrossSync.is_async:
298-
unary_interceptors = updated_channel._unary_unary_interceptors
299-
assert len(unary_interceptors) == 2
300-
assert GapicInterceptor in [type(i) for i in unary_interceptors]
301-
assert client._metrics_interceptor in unary_interceptors
302-
stream_interceptors = updated_channel._unary_stream_interceptors
303-
assert len(stream_interceptors) == 1
304-
assert client._metrics_interceptor in stream_interceptors
305-
else:
306-
assert isinstance(
307-
client.transport._logged_channel._interceptor, GapicInterceptor
308-
)
309-
assert updated_channel._interceptor == client._metrics_interceptor
310-
311-
@CrossSync.pytest
312-
async def test_channel_refresh_stress_test(self, table_id, instance_id, temp_rows):
313-
"""
314-
While swapping channels, consistently hit it with reads. Make sure no failures are found
269+
perform requests while swapping out the grpc channel. Requests should continue without error
315270
"""
316271
import time
317272

318273
await temp_rows.add_row(b"test_row")
319274
async with self._make_client() as client:
320275
client._channel_refresh_task.cancel()
276+
channel_wrapper = client.transport.grpc_channel
277+
first_channel = channel_wrapper._channel
321278
# swap channels frequently, with large grace windows
322279
client._channel_refresh_task = CrossSync.create_task(
323280
client._manage_channel,
324281
refresh_interval_min=0.1,
325282
refresh_interval_max=0.1,
326-
grace_period=0.2,
283+
grace_period=1,
327284
sync_executor=client._executor,
328285
)
329286

330287
# hit channels with frequent requests
331-
end_time = time.monotonic() + 1
288+
end_time = time.monotonic() + 3
332289
async with client.get_table(instance_id, table_id) as table:
333290
while time.monotonic() < end_time:
334291
# we expect a CancelledError if a channel is closed before completion
335292
rows = await table.read_rows({})
336293
assert len(rows) == 1
337294
await CrossSync.yield_to_event_loop()
295+
# ensure channel was updated
296+
updated_channel = channel_wrapper._channel
297+
assert updated_channel is not first_channel
298+
# ensure interceptors are kept (gapic's logging interceptor, and metric interceptor)
299+
if CrossSync.is_async:
300+
unary_interceptors = updated_channel._unary_unary_interceptors
301+
assert len(unary_interceptors) == 2
302+
assert GapicInterceptor in [type(i) for i in unary_interceptors]
303+
assert client._metrics_interceptor in unary_interceptors
304+
stream_interceptors = updated_channel._unary_stream_interceptors
305+
assert len(stream_interceptors) == 1
306+
assert client._metrics_interceptor in stream_interceptors
307+
else:
308+
assert isinstance(
309+
client.transport._logged_channel._interceptor, GapicInterceptor
310+
)
311+
assert updated_channel._interceptor == client._metrics_interceptor
338312

339313
@CrossSync.pytest
340314
@pytest.mark.usefixtures("target")

tests/system/data/test_system_autogen.py

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -221,55 +221,33 @@ def test_ping_and_warm(self, client, target):
221221
reason="emulator mode doesn't refresh channel",
222222
)
223223
def test_channel_refresh(self, table_id, instance_id, temp_rows):
224-
"""change grpc channel to refresh quickly, then schedule a read_rows call after refresh
225-
to ensure new channel is in place and works"""
226-
temp_rows.add_row(b"row_key_1")
227-
temp_rows.add_row(b"row_key_2")
228-
with self._make_client() as client:
229-
client._channel_refresh_task.cancel()
230-
client._channel_refresh_task = CrossSync._Sync_Impl.create_task(
231-
client._manage_channel,
232-
refresh_interval_min=0.25,
233-
refresh_interval_max=0.25,
234-
sync_executor=client._executor,
235-
)
236-
CrossSync._Sync_Impl.yield_to_event_loop()
237-
with client.get_table(instance_id, table_id) as table:
238-
rows = table.read_rows({})
239-
channel_wrapper = client.transport.grpc_channel
240-
first_channel = channel_wrapper._channel
241-
assert len(rows) == 2
242-
CrossSync._Sync_Impl.sleep(0.5)
243-
rows_after_refresh = table.read_rows({})
244-
assert len(rows_after_refresh) == 2
245-
assert client.transport.grpc_channel is channel_wrapper
246-
updated_channel = channel_wrapper._channel
247-
assert updated_channel is not first_channel
248-
assert isinstance(
249-
client.transport._logged_channel._interceptor, GapicInterceptor
250-
)
251-
assert updated_channel._interceptor == client._metrics_interceptor
252-
253-
def test_channel_refresh_stress_test(self, table_id, instance_id, temp_rows):
254-
"""While swapping channels, consistently hit it with reads. Make sure no failures are found"""
224+
"""perform requests while swapping out the grpc channel. Requests should continue without error"""
255225
import time
256226

257227
temp_rows.add_row(b"test_row")
258228
with self._make_client() as client:
259229
client._channel_refresh_task.cancel()
230+
channel_wrapper = client.transport.grpc_channel
231+
first_channel = channel_wrapper._channel
260232
client._channel_refresh_task = CrossSync._Sync_Impl.create_task(
261233
client._manage_channel,
262234
refresh_interval_min=0.1,
263235
refresh_interval_max=0.1,
264-
grace_period=0.2,
236+
grace_period=1,
265237
sync_executor=client._executor,
266238
)
267-
end_time = time.monotonic() + 1
239+
end_time = time.monotonic() + 3
268240
with client.get_table(instance_id, table_id) as table:
269241
while time.monotonic() < end_time:
270242
rows = table.read_rows({})
271243
assert len(rows) == 1
272244
CrossSync._Sync_Impl.yield_to_event_loop()
245+
updated_channel = channel_wrapper._channel
246+
assert updated_channel is not first_channel
247+
assert isinstance(
248+
client.transport._logged_channel._interceptor, GapicInterceptor
249+
)
250+
assert updated_channel._interceptor == client._metrics_interceptor
273251

274252
@pytest.mark.usefixtures("target")
275253
@CrossSync._Sync_Impl.Retry(

0 commit comments

Comments
 (0)