auto-t: iwd.py: use non_block_wait
This commit is contained in:
parent
80ee406e3e
commit
732871b601
|
@ -109,9 +109,7 @@ class AsyncOpAbstract(object):
|
||||||
self._exception = _convert_dbus_ex(ex)
|
self._exception = _convert_dbus_ex(ex)
|
||||||
|
|
||||||
def _wait_for_async_op(self):
|
def _wait_for_async_op(self):
|
||||||
context = ctx.mainloop.get_context()
|
ctx.non_block_wait(lambda s: s._is_completed, 30, self, exception=None)
|
||||||
while not self._is_completed:
|
|
||||||
context.iteration(may_block=True)
|
|
||||||
|
|
||||||
self._is_completed = False
|
self._is_completed = False
|
||||||
if self._exception is not None:
|
if self._exception is not None:
|
||||||
|
@ -1019,16 +1017,8 @@ class IWD(AsyncOpAbstract):
|
||||||
self._iwd_proc = self.namespace.start_iwd(iwd_config_dir,
|
self._iwd_proc = self.namespace.start_iwd(iwd_config_dir,
|
||||||
iwd_storage_dir)
|
iwd_storage_dir)
|
||||||
|
|
||||||
tries = 0
|
ctx.non_block_wait(self._bus.name_has_owner, 20, IWD_SERVICE,
|
||||||
while not self._bus.name_has_owner(IWD_SERVICE):
|
exception=TimeoutError('IWD has failed to start'))
|
||||||
if not ctx.args.gdb:
|
|
||||||
if tries > 200:
|
|
||||||
if start_iwd_daemon:
|
|
||||||
self.namespace.stop_process(self._iwd_proc)
|
|
||||||
self._iwd_proc = None
|
|
||||||
raise TimeoutError('IWD has failed to start')
|
|
||||||
tries += 1
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
self._devices = DeviceList(self)
|
self._devices = DeviceList(self)
|
||||||
|
|
||||||
|
@ -1074,27 +1064,13 @@ class IWD(AsyncOpAbstract):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _wait_for_object_condition(obj, condition_str, max_wait = 50):
|
def _wait_for_object_condition(obj, condition_str, max_wait = 50):
|
||||||
class TimeoutData:
|
def _eval_wrap(obj, condition_str):
|
||||||
_wait_timed_out = False
|
return eval(condition_str)
|
||||||
|
|
||||||
data = TimeoutData()
|
ctx.non_block_wait(_eval_wrap, max_wait, obj, condition_str,
|
||||||
|
exception=TimeoutError('[' + condition_str + ']'\
|
||||||
def wait_timeout_cb(data):
|
|
||||||
data._wait_timed_out = True
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
|
||||||
timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb, data)
|
|
||||||
context = ctx.mainloop.get_context()
|
|
||||||
while not eval(condition_str):
|
|
||||||
context.iteration(may_block=True)
|
|
||||||
if data._wait_timed_out and ctx.args.gdb == None:
|
|
||||||
raise TimeoutError('[' + condition_str + ']'\
|
|
||||||
' condition was not met in '\
|
' condition was not met in '\
|
||||||
+ str(max_wait) + ' sec')
|
+ str(max_wait) + ' sec'))
|
||||||
finally:
|
|
||||||
if not data._wait_timed_out:
|
|
||||||
GLib.source_remove(timeout)
|
|
||||||
|
|
||||||
def wait_for_object_condition(self, *args, **kwargs):
|
def wait_for_object_condition(self, *args, **kwargs):
|
||||||
self._wait_for_object_condition(*args, **kwargs)
|
self._wait_for_object_condition(*args, **kwargs)
|
||||||
|
@ -1108,22 +1084,7 @@ class IWD(AsyncOpAbstract):
|
||||||
This allows an object to be checked for a state transition without any
|
This allows an object to be checked for a state transition without any
|
||||||
intermediate state changes.
|
intermediate state changes.
|
||||||
'''
|
'''
|
||||||
self._wait_timed_out = False
|
def _eval_from_to(obj, from_str, to_str):
|
||||||
|
|
||||||
def wait_timeout_cb():
|
|
||||||
self._wait_timed_out = True
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Does initial condition pass?
|
|
||||||
if not eval(from_str):
|
|
||||||
raise Exception("initial condition [%s] not met" % from_str)
|
|
||||||
|
|
||||||
try:
|
|
||||||
timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb)
|
|
||||||
context = ctx.mainloop.get_context()
|
|
||||||
while True:
|
|
||||||
context.iteration(may_block=True)
|
|
||||||
|
|
||||||
# If neither the initial or expected condition evaluate the
|
# If neither the initial or expected condition evaluate the
|
||||||
# object must be in another unexpected state.
|
# object must be in another unexpected state.
|
||||||
if not eval(from_str) and not eval(to_str):
|
if not eval(from_str) and not eval(to_str):
|
||||||
|
@ -1132,30 +1093,21 @@ class IWD(AsyncOpAbstract):
|
||||||
|
|
||||||
# Initial condition does not evaluate but expected does, pass
|
# Initial condition does not evaluate but expected does, pass
|
||||||
if not eval(from_str) and eval(to_str):
|
if not eval(from_str) and eval(to_str):
|
||||||
break
|
return True
|
||||||
|
|
||||||
if self._wait_timed_out and ctx.args.gdb == None:
|
|
||||||
raise TimeoutError('[' + to_str + ']'\
|
|
||||||
' condition was not met in '\
|
|
||||||
+ str(max_wait) + ' sec')
|
|
||||||
finally:
|
|
||||||
if not self._wait_timed_out:
|
|
||||||
GLib.source_remove(timeout)
|
|
||||||
|
|
||||||
def wait(self, time):
|
|
||||||
self._wait_timed_out = False
|
|
||||||
def wait_timeout_cb():
|
|
||||||
self._wait_timed_out = True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
# Does initial condition pass?
|
||||||
timeout = GLib.timeout_add(int(time * 1000), wait_timeout_cb)
|
if not eval(from_str):
|
||||||
context = ctx.mainloop.get_context()
|
raise Exception("initial condition [%s] not met" % from_str)
|
||||||
while not self._wait_timed_out:
|
|
||||||
context.iteration(may_block=True)
|
ctx.non_block_wait(_eval_from_to, max_wait, obj, from_str, to_str,
|
||||||
finally:
|
exception=TimeoutError('[' + to_str + ']'\
|
||||||
if not self._wait_timed_out:
|
' condition was not met in '\
|
||||||
GLib.source_remove(timeout)
|
+ str(max_wait) + ' sec'))
|
||||||
|
|
||||||
|
def wait(self, time):
|
||||||
|
ctx.non_block_wait(lambda : False, time, exception=False)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def clear_storage(storage_dir=IWD_STORAGE_DIR):
|
def clear_storage(storage_dir=IWD_STORAGE_DIR):
|
||||||
|
@ -1200,21 +1152,8 @@ class IWD(AsyncOpAbstract):
|
||||||
if not wait_to_appear:
|
if not wait_to_appear:
|
||||||
return list(self._devices.values() if not p2p else self._devices.p2p_dict.values())
|
return list(self._devices.values() if not p2p else self._devices.p2p_dict.values())
|
||||||
|
|
||||||
self._wait_timed_out = False
|
ctx.non_block_wait(lambda s, n: len(s._devices) >= n, max_wait, self, wait_to_appear,
|
||||||
def wait_timeout_cb():
|
exception=TimeoutError('IWD has no associated devices'))
|
||||||
self._wait_timed_out = True
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
|
||||||
timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb)
|
|
||||||
context = ctx.mainloop.get_context()
|
|
||||||
while len(self._devices) < wait_to_appear:
|
|
||||||
context.iteration(may_block=True)
|
|
||||||
if self._wait_timed_out:
|
|
||||||
raise TimeoutError('IWD has no associated devices')
|
|
||||||
finally:
|
|
||||||
if not self._wait_timed_out:
|
|
||||||
GLib.source_remove(timeout)
|
|
||||||
|
|
||||||
return list(self._devices.values() if not p2p else self._devices.p2p_dict.values())[:wait_to_appear]
|
return list(self._devices.values() if not p2p else self._devices.p2p_dict.values())[:wait_to_appear]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue