1414import zeroconf as r
1515from zeroconf import ServiceBrowser , ServiceInfo , Zeroconf , const
1616
17+ from . import _inject_response
18+
1719log = logging .getLogger ('zeroconf' )
1820original_logging_level = logging .NOTSET
1921
@@ -153,7 +155,7 @@ def on_service_state_change(zeroconf, service_type, state_change, name):
153155 # force receive on oversized packet
154156 zc .send (out , const ._MDNS_ADDR , const ._MDNS_PORT )
155157 zc .send (out , const ._MDNS_ADDR , const ._MDNS_PORT )
156- time .sleep (2.0 )
158+ time .sleep (0.3 )
157159 zeroconf .log .debug (
158160 'warn %d debug %d was %s' ,
159161 mocked_log_warn .call_count ,
@@ -162,8 +164,8 @@ def on_service_state_change(zeroconf, service_type, state_change, name):
162164 )
163165 assert mocked_log_debug .call_count > call_counts [0 ]
164166
165- # close our zeroconf which will close the sockets
166- zc .close ()
167+ # close our zeroconf which will close the sockets
168+ zc .close ()
167169
168170 def verify_name_change (self , zc , type_ , name , number_hosts ):
169171 desc = {'path' : '/~paulsm/' }
@@ -201,17 +203,11 @@ def verify_name_change(self, zc, type_, name, number_hosts):
201203 assert info_service2 .name .split ('.' )[0 ] == '%s-%d' % (name , number_hosts + 1 )
202204
203205 def generate_many_hosts (self , zc , type_ , name , number_hosts ):
204- records_per_server = 2
205206 block_size = 25
206207 number_hosts = int (((number_hosts - 1 ) / block_size + 1 )) * block_size
207208 for i in range (1 , number_hosts + 1 ):
208209 next_name = name if i == 1 else '%s-%d' % (name , i )
209210 self .generate_host (zc , next_name , type_ )
210- if i % block_size == 0 :
211- sleep_count = 0
212- while sleep_count < 40 and i * records_per_server > len (zc .cache .entries_with_name (type_ )):
213- sleep_count += 1
214- time .sleep (0.05 )
215211
216212 @staticmethod
217213 def generate_host (zc , host_name , type_ ):
@@ -233,4 +229,4 @@ def generate_host(zc, host_name, type_):
233229 ),
234230 0 ,
235231 )
236- zc . send (out )
232+ _inject_response ( zc , r . DNSIncoming (out . packets ()[ 0 ]) )
0 commit comments