~robru/python-dbusmock/querycalls

« back to all changes in this revision

Viewing changes to dbusmock/testcase.py

  • Committer: Martin Pitt
  • Date: 2012-12-19 14:48:11 UTC
  • Revision ID: martin.pitt@ubuntu.com-20121219144811-tnp2psbpd4a0axhy
Fix race condition in waiting for mock to get online on the bus, by avoiding triggering D-BUS service activation with system-installed services.

Show diffs side-by-side

added added

removed removed

Lines of Context:
139
139
 
140
140
        timeout = 50
141
141
        last_exc = None
 
142
        # we check whether the name is owned first, to avoid race conditions
 
143
        # with service activation; once it's owned, wait until we can actually
 
144
        # call methods
142
145
        while timeout > 0:
143
 
            try:
144
 
                p = dbus.Interface(bus.get_object(dest, path),
145
 
                                   dbus_interface=dbus.INTROSPECTABLE_IFACE)
146
 
                p.Introspect()
147
 
                break
148
 
            except dbus.exceptions.DBusException as e:
149
 
                last_exc = e
150
 
                if '.UnknownInterface' in str(e):
 
146
            if bus.name_has_owner(dest):
 
147
                try:
 
148
                    p = dbus.Interface(bus.get_object(dest, path),
 
149
                                       dbus_interface=dbus.INTROSPECTABLE_IFACE)
 
150
                    p.Introspect()
151
151
                    break
152
 
                pass
 
152
                except dbus.exceptions.DBusException as e:
 
153
                    last_exc = e
 
154
                    if '.UnknownInterface' in str(e):
 
155
                        break
 
156
                    pass
153
157
 
154
158
            timeout -= 1
155
159
            time.sleep(0.1)