@@ -223,7 +223,7 @@ async def test__start_background_channel_refresh_task_exists(self):
223223 @CrossSync .pytest
224224 async def test__start_background_channel_refresh (self ):
225225 # should create background tasks for each channel
226- client = self ._make_client (project = "project-id" )
226+ client = self ._make_client (project = "project-id" , use_emulator = False )
227227 with mock .patch .object (
228228 client , "_ping_and_warm_instances" , CrossSync .Mock ()
229229 ) as ping_and_warm :
@@ -366,7 +366,7 @@ async def test__manage_channel_first_sleep(
366366 with mock .patch .object (CrossSync , "event_wait" ) as sleep :
367367 sleep .side_effect = asyncio .CancelledError
368368 try :
369- client = self ._make_client (project = "project-id" )
369+ client = self ._make_client (project = "project-id" , use_emulator = False )
370370 client ._channel_init_time = - wait_time
371371 await client ._manage_channel (refresh_interval , refresh_interval )
372372 except asyncio .CancelledError :
@@ -395,32 +395,29 @@ async def test__manage_channel_ping_and_warm(self):
395395 _LoggingClientInterceptor as Interceptor ,
396396 )
397397
398- client_mock = mock .Mock ()
399- client_mock .transport ._interceptor = Interceptor ()
400- client_mock ._is_closed .is_set .return_value = False
401- client_mock ._channel_init_time = time .monotonic ()
402- orig_channel = client_mock .transport .grpc_channel
398+ client = self ._make_client (project = "project-id" , use_emulator = True )
399+ orig_channel = client .transport .grpc_channel
403400 # should ping an warm all new channels, and old channels if sleeping
404401 sleep_tuple = (
405402 (asyncio , "sleep" ) if CrossSync .is_async else (threading .Event , "wait" )
406403 )
407- with mock .patch .object (* sleep_tuple ):
408- # stop process after close is called
409- orig_channel . close . side_effect = asyncio .CancelledError
410- ping_and_warm = client_mock ._ping_and_warm_instances = CrossSync .Mock ()
404+ with mock .patch .object (* sleep_tuple ) as sleep_mock :
405+ # stop process after loop
406+ sleep_mock . side_effect = [ None , asyncio .CancelledError ]
407+ ping_and_warm = client ._ping_and_warm_instances = CrossSync .Mock ()
411408 # should ping and warm old channel then new if sleep > 0
412409 try :
413- await self . _get_target_class (). _manage_channel (client_mock , 10 )
410+ await client . _manage_channel (10 )
414411 except asyncio .CancelledError :
415412 pass
416413 # should have called at loop start, and after replacement
417414 assert ping_and_warm .call_count == 2
418415 # should have replaced channel once
419- assert client_mock .transport ._grpc_channel != orig_channel
416+ assert client .transport .grpc_channel . _channel != orig_channel
420417 # make sure new and old channels were warmed
421418 called_with = [call [1 ]["channel" ] for call in ping_and_warm .call_args_list ]
422419 assert orig_channel in called_with
423- assert client_mock .transport .grpc_channel in called_with
420+ assert client .transport .grpc_channel . _channel in called_with
424421
425422 @CrossSync .pytest
426423 @pytest .mark .parametrize (
@@ -438,8 +435,6 @@ async def test__manage_channel_sleeps(
438435 import time
439436 import random
440437
441- channel = mock .Mock ()
442- channel .close = CrossSync .Mock ()
443438 with mock .patch .object (random , "uniform" ) as uniform :
444439 uniform .side_effect = lambda min_ , max_ : min_
445440 with mock .patch .object (time , "time" ) as time_mock :
@@ -448,8 +443,7 @@ async def test__manage_channel_sleeps(
448443 sleep .side_effect = [None for i in range (num_cycles - 1 )] + [
449444 asyncio .CancelledError
450445 ]
451- client = self ._make_client (project = "project-id" )
452- client .transport ._grpc_channel = channel
446+ client = self ._make_client (project = "project-id" , use_emulator = True )
453447 with mock .patch .object (
454448 client .transport , "create_channel" , CrossSync .Mock
455449 ):
@@ -478,7 +472,7 @@ async def test__manage_channel_random(self):
478472 uniform .return_value = 0
479473 try :
480474 uniform .side_effect = asyncio .CancelledError
481- client = self ._make_client (project = "project-id" )
475+ client = self ._make_client (project = "project-id" , use_emulator = False )
482476 except asyncio .CancelledError :
483477 uniform .side_effect = None
484478 uniform .reset_mock ()
@@ -512,7 +506,7 @@ async def test__manage_channel_refresh(self, num_cycles):
512506 CrossSync .grpc_helpers , "create_channel"
513507 ) as create_channel :
514508 create_channel .return_value = new_channel
515- client = self ._make_client (project = "project-id" )
509+ client = self ._make_client (project = "project-id" , use_emulator = False )
516510 create_channel .reset_mock ()
517511 try :
518512 await client ._manage_channel (
0 commit comments