@@ -487,7 +487,7 @@ def test_backoff():
487487 start_time = time .monotonic () * 1000
488488 initial_query_interval = _services_browser ._BROWSER_TIME / 1000
489489
490- def current_time_millis ():
490+ def _current_time_millis ():
491491 """Current system time in milliseconds"""
492492 return start_time + time_offset * 1000
493493
@@ -496,19 +496,34 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()):
496496 got_query .set ()
497497 old_send (out , addr = addr , port = port , v6_flow_scope = v6_flow_scope )
498498
499+ class ServiceBrowserWithPatchedTime (_services_browser .ServiceBrowser ):
500+ def _async_start (self ) -> None :
501+ """Generate the next time and setup listeners.
502+
503+ Must be called by uses of this base class after they
504+ have finished setting their properties.
505+ """
506+ super ()._async_start ()
507+ self .query_scheduler .start (_current_time_millis ())
508+
509+ def _async_send_ready_queries_schedule_next (self ):
510+ if self .done or self .zc .done :
511+ return
512+ now = _current_time_millis ()
513+ self ._async_send_ready_queries (now )
514+ self ._async_schedule_next (now )
515+
499516 # patch the zeroconf send
500517 # patch the zeroconf current_time_millis
501518 # patch the backoff limit to prevent test running forever
502519 with patch .object (zeroconf_browser , "async_send" , send ), patch .object (
503- _services_browser , "current_time_millis" , current_time_millis
504- ), patch .object (_services_browser , "_BROWSER_BACKOFF_LIMIT" , 10 ), patch .object (
505- _services_browser , "_FIRST_QUERY_DELAY_RANDOM_INTERVAL" , (0 , 0 )
506- ):
520+ _services_browser , "_BROWSER_BACKOFF_LIMIT" , 10
521+ ), patch .object (_services_browser , "_FIRST_QUERY_DELAY_RANDOM_INTERVAL" , (0 , 0 )):
507522 # dummy service callback
508523 def on_service_state_change (zeroconf , service_type , state_change , name ):
509524 pass
510525
511- browser = ServiceBrowser (zeroconf_browser , type_ , [on_service_state_change ])
526+ browser = ServiceBrowserWithPatchedTime (zeroconf_browser , type_ , [on_service_state_change ])
512527
513528 try :
514529 # Test that queries are sent at increasing intervals
0 commit comments