diff --git a/autotests/util/ead.py b/autotests/util/ead.py index 3a613bbe..8f333a8a 100644 --- a/autotests/util/ead.py +++ b/autotests/util/ead.py @@ -81,12 +81,8 @@ class EAD(iwd.AsyncOpAbstract): _adapters = None def __init__(self): - tries = 0 - while not self._bus.name_has_owner(EAD_SERVICE): - if tries > 200: - raise TimeoutError('IWD has failed to start') - tries += 1 - time.sleep(0.1) + ctx.non_block_wait(self._bus.name_has_owner, 20, EAD_SERVICE, + exception=TimeoutError('EAD has failed to start')) self._adapters = AdapterList(self) @@ -103,21 +99,8 @@ class EAD(iwd.AsyncOpAbstract): if not wait_to_appear: return list(self._adapters.values()) - self._wait_timed_out = False - def wait_timeout_cb(): - 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._adapters) < 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) + ctx.non_block_wait(lambda s, num : len(s._adapters) >= num, max_wait, self, wait_to_appear, + exception=TimeoutError('EAD has no associated devices')) return list(self._adapters.values())