'If the L{Deferred} returned by L{DNSDatagramProtocol.query} fires with
a failure, the L{DNSDatagramProtocol} is still disconnected from its
transport.'

def test_protocolShutDownAfterFailure(self):

    class ExpectedException(Exception, ):
        pass
    resolver = client.Resolver(servers=[('example.com', 53)])
    protocols = []
    result = defer.Deferred()
    class FakeProtocol(object, ):
        def __init__(self):
            self.transport = StubPort()
        def query(self, address, query, timeout=10, id=None):
            protocols.append(self)
            return result
    resolver._connectedProtocol = FakeProtocol
    queryResult = resolver.query(dns.Query('foo.example.com'))
    self.assertFalse(protocols[0].transport.disconnected)
    result.errback(failure.Failure(ExpectedException()))
    self.assertTrue(protocols[0].transport.disconnected)
    return self.assertFailure(queryResult, ExpectedException)
