1818from azure .iot .device .iothub .sync_handler_manager import MESSAGE , METHOD , TWIN_DP_PATCH
1919from azure .iot .device .iothub .inbox_manager import InboxManager
2020from azure .iot .device .iothub .aio .async_inbox import AsyncClientInbox
21+ from tests .unit .helpers import EVENTUAL_TIMEOUT
2122
2223logging .basicConfig (level = logging .DEBUG )
2324
@@ -413,7 +414,7 @@ async def test_handler_invoked(
413414 mock_obj = mocker .MagicMock ()
414415 inbox .put (mock_obj )
415416 # Wait for the handler invocation to complete
416- await async_poll_until (lambda : handler_checker .handler_called , timeout = 5 )
417+ await async_poll_until (lambda : handler_checker .handler_called , timeout = EVENTUAL_TIMEOUT )
417418
418419 # Handler has been called with the item from the inbox
419420 assert handler_checker .handler_called is True
@@ -441,7 +442,9 @@ async def test_handler_invoked_multiple(
441442 for _ in range (5 ):
442443 inbox .put (mocker .MagicMock ())
443444 # Wait for all handler invocations to complete
444- await async_poll_until (lambda : handler_checker .handler_call_count >= 5 , timeout = 5 )
445+ await async_poll_until (
446+ lambda : handler_checker .handler_call_count >= 5 , timeout = EVENTUAL_TIMEOUT
447+ )
445448
446449 # Handler has been called 5 times
447450 assert handler_checker .handler_call_count == 5
@@ -550,7 +553,7 @@ async def coro_handler(arg):
550553 # Add an item to corresponding inbox, triggering the handler
551554 inbox .put (mocker .MagicMock ())
552555 # Wait for the background exception handler to be called
553- await async_poll_until (lambda : background_exc_spy .call_count >= 1 , timeout = 5 )
556+ await async_poll_until (lambda : background_exc_spy .call_count >= 1 , timeout = EVENTUAL_TIMEOUT )
554557 # Background exception handler was called
555558 assert background_exc_spy .call_count == 1
556559 e = background_exc_spy .call_args [0 ][0 ]
@@ -567,7 +570,7 @@ async def coro_handler(arg):
567570 # Add an item to corresponding inbox, triggering the handler
568571 inbox .put (mocker .MagicMock ())
569572 # Wait for the background exception handler to be called
570- await async_poll_until (lambda : background_exc_spy .call_count >= 1 , timeout = 5 )
573+ await async_poll_until (lambda : background_exc_spy .call_count >= 1 , timeout = EVENTUAL_TIMEOUT )
571574 # Background exception handler was called
572575 assert background_exc_spy .call_count == 1
573576 e = background_exc_spy .call_args [0 ][0 ]
@@ -596,7 +599,8 @@ def handler1(arg):
596599 inbox .put (mocker .MagicMock ())
597600 # Wait for handler1 to replace itself with handler2
598601 await async_poll_until (
599- lambda : getattr (handler_manager , handler_name ) is handler2 , timeout = 5
602+ lambda : getattr (handler_manager , handler_name ) is handler2 ,
603+ timeout = EVENTUAL_TIMEOUT ,
600604 )
601605 # The set handler (handler1) has been replaced with a new handler (handler2)
602606 assert getattr (handler_manager , handler_name ) is not handler1
@@ -605,15 +609,16 @@ def handler1(arg):
605609 inbox .put (mocker .MagicMock ())
606610 # Wait for handler2 to replace itself with the mock
607611 await async_poll_until (
608- lambda : getattr (handler_manager , handler_name ) is mock_handler , timeout = 5
612+ lambda : getattr (handler_manager , handler_name ) is mock_handler ,
613+ timeout = EVENTUAL_TIMEOUT ,
609614 )
610615 # The set handler (handler2) has now been replaced by a mock handler
611616 assert getattr (handler_manager , handler_name ) is not handler2
612617 assert getattr (handler_manager , handler_name ) is mock_handler
613618 # Add a new item to the inbox
614619 inbox .put (mocker .MagicMock ())
615620 # Wait for the mock handler invocation to complete
616- await async_poll_until (lambda : mock_handler .call_count >= 1 , timeout = 5 )
621+ await async_poll_until (lambda : mock_handler .call_count >= 1 , timeout = EVENTUAL_TIMEOUT )
617622 # The mock was now called
618623 assert getattr (handler_manager , handler_name ).call_count == 1
619624
@@ -706,7 +711,9 @@ async def test_handler_invoked(
706711 # Add the event to the client inbox
707712 inbox .put (event )
708713 # Wait for the handler invocation to complete
709- await async_poll_until (lambda : handler_checker .handler_call_count >= 1 , timeout = 5 )
714+ await async_poll_until (
715+ lambda : handler_checker .handler_call_count >= 1 , timeout = EVENTUAL_TIMEOUT
716+ )
710717
711718 # Handler has been called with the arguments from the event
712719 assert handler_checker .handler_call_count == 1
@@ -716,7 +723,7 @@ async def test_handler_invoked(
716723 non_matching_event = client_event .ClientEvent ("NON_MATCHING_EVENT" )
717724 inbox .put (non_matching_event )
718725 # Wait for the runner to consume the non-matching event
719- await async_poll_until (inbox .empty , timeout = 5 )
726+ await async_poll_until (inbox .empty , timeout = EVENTUAL_TIMEOUT )
720727
721728 # Handler has not been called again
722729 assert handler_checker .handler_call_count == 1
@@ -743,7 +750,9 @@ async def test_handler_invoked_multiple(
743750 for _ in range (5 ):
744751 inbox .put (event )
745752 # Wait for all handler invocations to complete
746- await async_poll_until (lambda : handler_checker .handler_call_count >= 5 , timeout = 5 )
753+ await async_poll_until (
754+ lambda : handler_checker .handler_call_count >= 5 , timeout = EVENTUAL_TIMEOUT
755+ )
747756
748757 # Handler has been called 5 times
749758 assert handler_checker .handler_call_count == 5
@@ -777,7 +786,7 @@ async def coro_handler(*args):
777786 # Add an item to corresponding inbox, triggering the handler
778787 inbox .put (event )
779788 # Wait for the background exception handler to be called
780- await async_poll_until (lambda : background_exc_spy .call_count >= 1 , timeout = 5 )
789+ await async_poll_until (lambda : background_exc_spy .call_count >= 1 , timeout = EVENTUAL_TIMEOUT )
781790 # Background exception handler was called
782791 assert background_exc_spy .call_count == 1
783792 e = background_exc_spy .call_args [0 ][0 ]
@@ -794,7 +803,7 @@ async def coro_handler(*args):
794803 # Add an item to corresponding inbox, triggering the handler
795804 inbox .put (event )
796805 # Wait for the background exception handler to be called
797- await async_poll_until (lambda : background_exc_spy .call_count >= 1 , timeout = 5 )
806+ await async_poll_until (lambda : background_exc_spy .call_count >= 1 , timeout = EVENTUAL_TIMEOUT )
798807 # Background exception handler was called
799808 assert background_exc_spy .call_count == 1
800809 e = background_exc_spy .call_args [0 ][0 ]
@@ -823,7 +832,8 @@ def handler1(*args):
823832 inbox .put (event )
824833 # Wait for handler1 to replace itself with handler2
825834 await async_poll_until (
826- lambda : getattr (handler_manager , handler_name ) is handler2 , timeout = 5
835+ lambda : getattr (handler_manager , handler_name ) is handler2 ,
836+ timeout = EVENTUAL_TIMEOUT ,
827837 )
828838 # The set handler (handler1) has been replaced with a new handler (handler2)
829839 assert getattr (handler_manager , handler_name ) is not handler1
@@ -832,15 +842,16 @@ def handler1(*args):
832842 inbox .put (event )
833843 # Wait for handler2 to replace itself with the mock
834844 await async_poll_until (
835- lambda : getattr (handler_manager , handler_name ) is mock_handler , timeout = 5
845+ lambda : getattr (handler_manager , handler_name ) is mock_handler ,
846+ timeout = EVENTUAL_TIMEOUT ,
836847 )
837848 # The set handler (handler2) has now been replaced by a mock handler
838849 assert getattr (handler_manager , handler_name ) is not handler2
839850 assert getattr (handler_manager , handler_name ) is mock_handler
840851 # Add a new item to the inbox
841852 inbox .put (event )
842853 # Wait for the mock handler invocation to complete
843- await async_poll_until (lambda : mock_handler .call_count >= 1 , timeout = 5 )
854+ await async_poll_until (lambda : mock_handler .call_count >= 1 , timeout = EVENTUAL_TIMEOUT )
844855 # The mock was now called
845856 assert getattr (handler_manager , handler_name ).call_count == 1
846857
0 commit comments