Bug 32074 - should run regression tests against a mock Avahi by default
Summary: should run regression tests against a mock Avahi by default
Status: RESOLVED FIXED
Alias: None
Product: Telepathy
Classification: Unclassified
Component: salut (show other bugs)
Version: git master
Hardware: Other All
: medium normal
Assignee: Jonny Lamb
QA Contact: Telepathy bugs list
URL: http://cgit.freedesktop.org/~jonny/te...
Whiteboard: review+
Keywords: patch
Depends on:
Blocks:
 
Reported: 2010-12-03 02:49 UTC by Simon McVittie
Modified: 2011-04-07 02:21 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Simon McVittie 2010-12-03 02:49:22 UTC
The Salut regression tests currently work on the real network, causing mDNS spam for everyone around you. This also means that some tests (mostly those related to iChat) can't work if you're running another instance of llXMPP (probably the instance of Salut you're using for Empathy!).

Tomeu has a branch to use a fake Avahi daemon for the tests, but I believe he's stopped working on this. I want to make Salut into a proper modern CM (tests, TpBaseContactList, GIO, etc.) so I'll probably pick this up myself.
Comment 1 Simon McVittie 2010-12-03 09:05:09 UTC
In general this looks good. Some very brief notes for my own reference:

--- a/tests/twisted/avahi/file-transfer/test-receive-file-ipv6.py
+++ b/tests/twisted/avahi/file-transfer/test-receive-file-ipv6.py
@@ -36,7 +36,8 @@ class TestReceiveFileIPv6(ReceiveFileTest):
         service = e.service
         service.resolve()
 
-        e = self.q.expect('service-resolved', service = service)
+        e = self.q.expect('service-resolved', service = service,
+                          protocol = avahi.PROTO_INET6)

Check that this works for the real network

diff --git a/tests/twisted/avahi/file-transfer/test-send-file-to-unknown-contact.py b/tests/twisted/avahi/file-transfer/test-send-file-to-unknown-contact.py
index cab907c..83ec8a1 100644
--- a/tests/twisted/avahi/file-transfer/test-send-file-to-unknown-contact.py
+++ b/tests/twisted/avahi/file-transfer/test-send-file-to-unknown-contact.py
@@ -19,7 +19,8 @@ class SendFileTransferToUnknownContactTest(SendFileTest):
         try:
             self.request_ft_channel()
         except dbus.DBusException, e:
-            assert e.get_dbus_name() == cs.NOT_AVAILABLE
+            if e.get_dbus_name() != cs.NOT_AVAILABLE:
+                raise

Good independently, but call_async + expect would be even better

+def get_domain():
+    full_domain = socket.getfqdn()
+    if '.' in full_domain:
+        return full_domain.split('.', 1)[1]
+    else:
+        return ''

Shouldn't use this, laptops' FQDNs are meaningless. All we need is
Avahi's idea of the hostname (which we control anyway, so set it to
mockavahi) and Avahi's advertising domain (.local).

+            emit_signal(service_resolver.object_path,
+                        AVAHI_IFACE_SERVICE_RESOLVER, 'Failure',
+                        service_resolver.client, 's',
+                        'fill with a proper error string')

Indeed.

+    def _resolve_hostname(self, protocol, hostname):

I'm dubious about needing this. Surely we ought to advertise everything
we need on mDNS?

+    @dbus.service.method(dbus_interface=AVAHI_IFACE_SERVER,
+                         in_signature='', out_signature='s')
+    def GetHostName(self):
+        return socket.gethostname()

Hard-code this?

+    @dbus.service.method(dbus_interface=AVAHI_IFACE_SERVER,
+                         in_signature='', out_signature='s')
+    def GetHostNameFqdn(self):
+        return socket.getfqdn()

Hard-code this?

+
+    @dbus.service.method(dbus_interface=AVAHI_IFACE_SERVER,
+                         in_signature='', out_signature='s')
+    def GetDomainName(self):
+        return get_domain()

And this?

+    @dbus.service.method(dbus_interface=AVAHI_IFACE_SERVER,
+                         in_signature='', out_signature='i')
+    def GetState(self):
+        return 2

Magic number

+    @dbus.service.method(dbus_interface=AVAHI_IFACE_ENTRY_GROUP,
+                         in_signature='', out_signature='')
+    def Commit(self):
+        self._set_state(1)
+        glib.idle_add(lambda: self._set_state(2))

Magic numbers

+    tests_dir = os.path.dirname(__file__)
+    avahimock_path = os.path.join(tests_dir, 'avahimock.py')
+    Popen([avahimock_path])

Isn't there a better fork/exec we could use?

We could even use service activation, if we make the mock Avahi use the starter bus.

diff --git a/tests/twisted/tools/org.freedesktop.Avahi.service b/tests/twisted/tools/org.freedesktop.Avahi.service
new file mode 100644
index 0000000..c5c500c
--- /dev/null
+++ b/tests/twisted/tools/org.freedesktop.Avahi.service
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.freedesktop.Avahi
+Exec=dumb

Should use the fake-launch helper from MC, or not be activatable at all

diff --git a/tests/twisted/tools/with-session-bus.sh b/tests/twisted/tools/with-session-bus.sh

Copy to telepathy-glib
Comment 2 Jonny Lamb 2011-04-06 05:13:38 UTC
I've taken this branch over.

(In reply to comment #1)
> -        e = self.q.expect('service-resolved', service = service)
> +        e = self.q.expect('service-resolved', service = service,
> +                          protocol = avahi.PROTO_INET6)
> 
> Check that this works for the real network

Done.

>          try:
>              self.request_ft_channel()
>          except dbus.DBusException, e:
> -            assert e.get_dbus_name() == cs.NOT_AVAILABLE
> +            if e.get_dbus_name() != cs.NOT_AVAILABLE:
> +                raise
> 
> Good independently, but call_async + expect would be even better

This is actually a bit of a pain because request_ft_channel does more than just call CreateChannel synchronously. I'm going to leave this for now.

> +def get_domain():
> +    full_domain = socket.getfqdn()
> +    if '.' in full_domain:
> +        return full_domain.split('.', 1)[1]
> +    else:
> +        return ''
> 
> Shouldn't use this, laptops' FQDNs are meaningless. All we need is
> Avahi's idea of the hostname (which we control anyway, so set it to
> mockavahi) and Avahi's advertising domain (.local).

Done.

> +            emit_signal(service_resolver.object_path,
> +                        AVAHI_IFACE_SERVICE_RESOLVER, 'Failure',
> +                        service_resolver.client, 's',
> +                        'fill with a proper error string')
> 
> Indeed.

Done.

> +    @dbus.service.method(dbus_interface=AVAHI_IFACE_SERVER,
> +                         in_signature='', out_signature='s')
> +    def GetHostName(self):
> +        return socket.gethostname()
> 
> Hard-code this?

Done.

> +    @dbus.service.method(dbus_interface=AVAHI_IFACE_SERVER,
> +                         in_signature='', out_signature='s')
> +    def GetHostNameFqdn(self):
> +        return socket.getfqdn()
> 
> Hard-code this?

Done.

> +    @dbus.service.method(dbus_interface=AVAHI_IFACE_SERVER,
> +                         in_signature='', out_signature='s')
> +    def GetDomainName(self):
> +        return get_domain()
> 
> And this?

Done.

> +    @dbus.service.method(dbus_interface=AVAHI_IFACE_SERVER,
> +                         in_signature='', out_signature='i')
> +    def GetState(self):
> +        return 2
> 
> Magic number

Fixed.

> +    @dbus.service.method(dbus_interface=AVAHI_IFACE_ENTRY_GROUP,
> +                         in_signature='', out_signature='')
> +    def Commit(self):
> +        self._set_state(1)
> +        glib.idle_add(lambda: self._set_state(2))
> 
> Magic numbers

Fixed.

> +[D-BUS Service]
> +Name=org.freedesktop.Avahi
> +Exec=dumb
> 
> Should use the fake-launch helper from MC, or not be activatable at all

Deleted service file. We're not testing service activation here.
Comment 3 Jonny Lamb 2011-04-06 05:14:50 UTC
With real system avahi: 2:22.70

With mock avahi: 1:01.24

Not a bad speed increase.
Comment 4 Jonny Lamb 2011-04-06 07:31:54 UTC
Okay, cool, I get consistent passing of tests now, and I added support for switching the mock avahi off at runtime.

Reviewers should review from when I started working on the branch which starts at commit: "Merge remote branch 'smcv/mock-avahi'".

Cooooooooooool.
Comment 5 Will Thompson 2011-04-07 02:11:30 UTC
looks fine!
Comment 6 Jonny Lamb 2011-04-07 02:21:05 UTC
awesome lol


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.