about summary refs log tree commit diff
path: root/debian
diff options
context:
space:
mode:
authorTill Kamppeter <till.kamppeter@gmail.com>2019-07-02 22:27:01 +0200
committerTill Kamppeter <till.kamppeter@gmail.com>2019-07-02 22:27:01 +0200
commit40a02f6911c35bc60260f9a8cbe0edf4763cef69 (patch)
treea4a1031efe58dee231a404f12aab5d01d830038a /debian
parentb47c1b22b9619990d6b1669d76d0cd01452bf5d7 (diff)
nm.py autopkgtest: Improved implementation of adding timers for the main loops.
Diffstat (limited to 'debian')
-rwxr-xr-xdebian/tests/nm.py48
1 files changed, 35 insertions, 13 deletions
diff --git a/debian/tests/nm.py b/debian/tests/nm.py
index ab3571d3..8316e087 100755
--- a/debian/tests/nm.py
+++ b/debian/tests/nm.py
@@ -24,7 +24,7 @@ except ImportError:
 import gi
 
 gi.require_version('NM', '1.0')
-from gi.repository import NM, GLib
+from gi.repository import NM, GLib, Gio
 
 sys.path.append(os.path.dirname(__file__))
 import network_test_base
@@ -270,20 +270,31 @@ class NetworkManagerTest(network_test_base.NetworkTestBase):
 
         ml = GLib.MainLoop()
         self.cb_conn = None
+        self.cancel = Gio.Cancellable()
+        self.timeout_tag = 0
 
         def add_activate_cb(client, res, data):
-            self.cb_conn = self.nmclient.add_and_activate_connection_finish(res)
+            if (self.timeout_tag > 0):
+                GLib.source_remove(self.timeout_tag)
+                self.timeout_tag = 0
+            if (not self.cancel.is_cancelled()):
+                self.cb_conn = \
+                    self.nmclient.add_and_activate_connection_finish(res)
             ml.quit()
 
         def timeout_cb():
-            print("Main loop timed out!")
+            self.cancel.cancel()
+            self.timeout_tag = -1
             ml.quit()
-            return False
+            return GLib.SOURCE_REMOVE
 
-        self.nmclient.add_and_activate_connection_async(partial_conn, self.nmdev_w, ap.get_path(), None, add_activate_cb, None)
-        timeout_tag = GLib.timeout_add_seconds(300, timeout_cb)
+        self.nmclient.add_and_activate_connection_async(partial_conn, self.nmdev_w, ap.get_path(), self.cancel, add_activate_cb, None)
+        self.timeout_tag = GLib.timeout_add_seconds(300, timeout_cb)
         ml.run()
-        GLib.source_remove(timeout_tag)
+        self.cancel.reset()
+        if (self.timeout_tag < 0):
+            self.timeout_tag = 0
+            self.fail('Main loop for adding connection timed out!')
         self.assertNotEqual(self.cb_conn, None)
         active_conn = self.cb_conn
         self.cb_conn = None
@@ -678,20 +689,31 @@ Logs are in '%s'. When done, exit the shell.
 
             ml = GLib.MainLoop()
             self.cb_conn = None
+            self.cancel = Gio.Cancellable()
+            self.timeout_tag = 0
 
             def add_activate_cb(client, res, data):
-                self.cb_conn = self.nmclient.add_and_activate_connection_finish(res)
+                if (self.timeout_tag > 0):
+                    GLib.source_remove(self.timeout_tag)
+                    self.timeout_tag = 0
+                if (not self.cancel.is_cancelled()):
+                    self.cb_conn = \
+                        self.nmclient.add_and_activate_connection_finish(res)
                 ml.quit()
 
             def timeout_cb():
-                print("Main loop timed out!")
+                self.cancel.cancel()
+                self.timeout_tag = -1
                 ml.quit()
-                return False
+                return GLib.SOURCE_REMOVE
 
-            self.nmclient.add_and_activate_connection_async(partial_conn, self.nmdev_e, None, None, add_activate_cb, None)
-            timeout_tag = GLib.timeout_add_seconds(300, timeout_cb)
+            self.nmclient.add_and_activate_connection_async(partial_conn, self.nmdev_e, None, self.cancel, add_activate_cb, None)
+            self.timeout_tag = GLib.timeout_add_seconds(300, timeout_cb)
             ml.run()
-            GLib.source_remove(timeout_tag)
+            self.cancel.reset()
+            if (self.timeout_tag < 0):
+                self.timeout_tag = 0
+                self.fail('Main loop for adding connection timed out!')
             self.assertNotEqual(self.cb_conn, None)
             active_conn = self.cb_conn
             self.cb_conn = None