Some tests in pserv_services.tests.test_dhcp_probe_service:TestDHCPProbeService never fail

Bug #1363161 reported by Graham Binns
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
Fix Released
High
Unassigned

Bug Description

To reproduce:

1. Branch trunk
2. Edit src/provisioningserver/pserv_services/tests/test_dhcp_probe_service.py
3. Add a self.fail() call into one of the tests
4. Run bin/test.pserv pserv_services.tests.test_dhcp_probe_service:TestDHCPProbeService
5. See that for all except test_probe_is_initiated_in_new_thread and test_is_called_every_interval, the test that should fail doesn't.

This led to at least one bug being missed that should never have landed.

Related branches

Revision history for this message
Gavin Panella (allenap) wrote :

A few of the tests are assuming the presence of inlineCallbacks, but they're not decorated as such. See http://paste.ubuntu.com/8180104/ for a fix.

Revision history for this message
Graham Binns (gmb) wrote : Re: [Bug 1363161] [NEW] Some tests in pserv_services.tests.test_dhcp_probe_service:TestDHCPProbeService never fail

Thanks Gavin. Is there any way we can protect against this kind of stuff in
future? ISTM that this is going to happen again for people who aren't
twisted-savvy.

Revision history for this message
Gavin Panella (allenap) wrote :

> Is there any way we can protect against this kind of stuff in
> future? ISTM that this is going to happen again for people who
> aren't twisted-savvy.

Heh, it happens to people who *are* Twisted savvy.

When I do it, I see it as a lesson in making sure I see my tests
fail before I see them pass.

There's probably something we can do to testtools to make it fail
tests that return generators.

Revision history for this message
Gavin Panella (allenap) wrote :

This works, as a replacement for AsynchronousDeferredRunTest:
----

import types
from testtools import deferredruntest
from twisted.internet import defer

class InvalidTest(Exception):
    """Signifies that the test is invalid; it's not a good test."""

class TwistedRunTest(deferredruntest.AsynchronousDeferredRunTest):

    def _check_for_generator(self, result):
        if isinstance(result, types.GeneratorType):
            raise InvalidTest(
                "Test returned a generator. Should it be "
                "decorated with inlineCallbacks?")
        else:
            return result

    def _run_user(self, function, *args):
        d = defer.maybeDeferred(function, *args)
        d.addCallback(self._check_for_generator)
        d.addErrback(self._got_user_failure)
        return d

Revision history for this message
Gavin Panella (allenap) wrote :

I should have added that we should see to get this upstream into testtools.

Revision history for this message
Gavin Panella (allenap) wrote :

I put TwistedTestCase into a branch. It caught three tests in TestDHCPProbeService and one elsewhere. The three failed when decorated with inlineCallbacks, the one other passes.

Revision history for this message
Graham Binns (gmb) wrote :

You lovely man. I'll review it when I get chance if someone else doesn't
first.

Revision history for this message
Julian Edwards (julian-edwards) wrote : Re: [Bug 1363161] Re: Some tests in pserv_services.tests.test_dhcp_probe_service:TestDHCPProbeService never fail

Which is why we should always write tests that fail before writing code.

Revision history for this message
Graham Binns (gmb) wrote :

On 30 August 2014 05:51, Julian Edwards <email address hidden> wrote:

> Which is why we should always write tests that fail before writing code.
>

Agreed.

Revision history for this message
Gavin Panella (allenap) wrote :

This has been fixed for, I think, quite a long time.

Changed in maas:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.