LibsocialwebTest: don't try to keep ownership of name through tear_down()
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Fri, 15 Mar 2013 15:35:51 +0000 (15:35 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 20 Mar 2013 11:48:25 +0000 (11:48 +0000)
This is a step towards replacing with-session-bus*.sh with GTestDBus,
which cleans up our D-Bus connection while the test is still running.
If we do that without this change, then the NameLost callback is triggered
when we get disconnected from D-Bus, causing an assertion failure.

This also should reduce circular references, by making sure closures
that contain "this" get cleaned up.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=690830
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip@tecnocode.co.uk>
tests/lib/libsocialweb/backend.vala

index 0425278..ce082af 100644 (file)
@@ -304,6 +304,7 @@ public class LibsocialwebTest.Backend
 
   public bool debug { get; set; }
   private LibsocialwebServerTest lsw_server;
+  private uint _name_id = 0;
 
   public signal void ready ();
 
@@ -325,7 +326,7 @@ public class LibsocialwebTest.Backend
           assert_not_reached ();
         }
 
-      Bus.own_name (
+      this._name_id = Bus.own_name (
         BusType.SESSION, LIBSOCIALWEB_BUS_NAME,
         BusNameOwnerFlags.NONE,
         on_bus_aquired,
@@ -352,5 +353,10 @@ public class LibsocialwebTest.Backend
 
   public void tear_down ()
     {
+      if (this._name_id != 0)
+        {
+          Bus.unown_name (this._name_id);
+          this._name_id = 0;
+        }
     }
 }