@@ -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" )
0 commit comments