auto-t: Changed list_devices() wait_to_appear to int

The list_devices API has a race condition where sometimes it will
return zero or less than the expected number of devices and fail
the test. A fix is in place for when only a single devices is
expected, but some tests expect more than one device. This changes
wait_to_appear to an integer, and the caller can specify the number
of devices they expect to get back. The default stays as it was,
zero or "return cached devices".
This commit is contained in:
James Prestwood 2018-07-02 10:02:07 -07:00 committed by Denis Kenzior
parent fb1296e9c0
commit 003c1dbc97
1 changed files with 2 additions and 2 deletions

View File

@ -798,7 +798,7 @@ class IWD(AsyncOpAbstract):
assert not os.path.isabs(source)
shutil.copy(source, IWD_STORAGE_DIR)
def list_devices(self, wait_to_appear = False, max_wait = 15):
def list_devices(self, wait_to_appear = 0, max_wait = 15):
if not wait_to_appear:
return list(self._devices.values())
@ -809,7 +809,7 @@ class IWD(AsyncOpAbstract):
timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb)
context = mainloop.get_context()
while len(self._devices) == 0:
while len(self._devices) < wait_to_appear:
context.iteration(may_block=True)
if self._wait_timed_out:
raise TimeoutError('IWD has no associated devices')