mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-02-01 05:54:08 +01:00
autotests: Avoid periodic polling in the wait methods
Modify AsyncOpAbstract._wait_for_async_op and IWD.wait_for_object_condition to call context.iteration() in the blocking mode instead of calling context.pending() every 0.01s. This gets rid of busy-waiting and also ensures that the condition is checked after every single dbus (or other) event. This way a condition that potentially occurs for less than 0.01s can be reliably waited for.
This commit is contained in:
parent
1df2e18f61
commit
bb350a3b8e
@ -94,10 +94,7 @@ class AsyncOpAbstract(object):
|
|||||||
def _wait_for_async_op(self):
|
def _wait_for_async_op(self):
|
||||||
context = mainloop.get_context()
|
context = mainloop.get_context()
|
||||||
while not self._is_completed:
|
while not self._is_completed:
|
||||||
if context.pending():
|
context.iteration(may_block=True)
|
||||||
context.iteration()
|
|
||||||
else:
|
|
||||||
time.sleep(0.01)
|
|
||||||
|
|
||||||
self._is_completed = False
|
self._is_completed = False
|
||||||
if self._exception is not None:
|
if self._exception is not None:
|
||||||
@ -578,18 +575,20 @@ class IWD(AsyncOpAbstract):
|
|||||||
return _known_network_manager_if
|
return _known_network_manager_if
|
||||||
|
|
||||||
def wait_for_object_condition(self, obj, condition_str, max_wait = 15):
|
def wait_for_object_condition(self, obj, condition_str, max_wait = 15):
|
||||||
start = time.time()
|
self._wait_timed_out = False
|
||||||
|
def wait_timeout_cb():
|
||||||
|
self._wait_timed_out = True
|
||||||
|
return False
|
||||||
|
|
||||||
|
timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb)
|
||||||
context = mainloop.get_context()
|
context = mainloop.get_context()
|
||||||
while not eval(condition_str):
|
while not eval(condition_str):
|
||||||
if context.pending():
|
context.iteration(may_block=True)
|
||||||
context.iteration()
|
if self._wait_timed_out:
|
||||||
else:
|
raise TimeoutError('[' + condition_str + ']'\
|
||||||
now = time.time()
|
' condition was not met in '\
|
||||||
if (now - start) > max_wait:
|
+ str(max_wait) + ' sec')
|
||||||
raise TimeoutError('[' + condition_str + ']'\
|
GLib.source_remove(timeout)
|
||||||
' condition was not met in '\
|
|
||||||
+ str(max_wait) + ' sec')
|
|
||||||
time.sleep(0.01)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def clear_storage():
|
def clear_storage():
|
||||||
|
Loading…
Reference in New Issue
Block a user