diff mbox series

[6/8] auto-t: remove sleep in testAgent

Message ID 20220624230741.1957863-6-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [1/8] test-runner: remove reference to missing class member | expand

Commit Message

James Prestwood June 24, 2022, 11:07 p.m. UTC
The test here is verifying that a DBus Connect() call will still
work with 'other' agents registered. In this case it uses iwctl to
set a password, then call Connect() manually.

The problem here is that we have no way of knowing when iwctl fully
starts and registers its agent. There was a sleep in there but that
is unreliable and we occationally were still getting past that without
iwctl having started fully.

To fix this properly we need to wait for iwctl's agent service to appear
on the bus. Since the bus name is unknown we must first find all names,
then cross reference their PID's against the iwctl PID. This is done
using ListNames, and GetConnectionUnixProcessID APIs.
---
 autotests/testAgent/agent_test.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/autotests/testAgent/agent_test.py b/autotests/testAgent/agent_test.py
index e2d6e49e..c1dc8c7c 100644
--- a/autotests/testAgent/agent_test.py
+++ b/autotests/testAgent/agent_test.py
@@ -2,6 +2,7 @@ 
 
 import unittest
 import sys
+import dbus
 
 sys.path.append('../util')
 import iwd
@@ -56,11 +57,26 @@  class Test(unittest.TestCase):
         IWD.clear_storage()
 
     def test_connection_with_other_agent(self):
+        def wait_for_service_pid(pid):
+            dbus_object = ctx._bus.get_object('org.freedesktop.DBus',
+                                 '/org/freedesktop/DBus')
+            dbus_iface = dbus.Interface(dbus_object, 'org.freedesktop.DBus')
+
+            services = dbus_iface.ListNames()
+
+            for service in services:
+                bus_iface = dbus.Interface(dbus_object, "org.freedesktop.DBus")
+                if pid == int(bus_iface.GetConnectionUnixProcessID(service)):
+                    return True
+
+            return False
+
         wd = IWD()
 
         iwctl = ctx.start_process(['iwctl', '-P', 'secret_ssid2'])
+
         # Let iwctl to start and register its agent.
-        wd.wait(2)
+        ctx.non_block_wait(wait_for_service_pid, 10, iwctl.pid)
 
         self.check_connection(wd, 'ssid2')