~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/rabbit/tests/test_fixture.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-23 19:55:29 UTC
  • mfrom: (13047.3.18 job-start-cleanup)
  • Revision ID: launchpad@pqm.canonical.com-20110523195529-zq0tcaiqayia2c03
[r=allenap][no-qa] Fix a tight loop during RabbitMQ fixture set-up,
        and lots of other clean-ups and incremental improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
from amqplib import client_0_8 as amqp
11
11
from fixtures import EnvironmentVariableFixture
12
12
 
 
13
from lp.services.rabbit.testing.server import RabbitServer
13
14
from lp.testing import TestCase
14
 
from lp.services.rabbit.testing.server import RabbitServer
15
15
 
16
16
 
17
17
class TestRabbitFixture(TestCase):
21
21
        # .erlange.cookie has to be ignored, and ditto bogus HOME if other
22
22
        # tests fail to cleanup.
23
23
        self.useFixture(EnvironmentVariableFixture('HOME', '/nonsense/value'))
 
24
 
24
25
        fixture = RabbitServer()
25
 
        try:
26
 
            # Workaround failures-in-setup-not-attaching-details (if they did
27
 
            # we could use self.useFixture).
28
 
            self.addCleanup(self._gather_details, fixture.getDetails)
29
 
            fixture.setUp()
 
26
 
 
27
        # Work around failures-in-setup-not-attaching-details (if they did we
 
28
        # could use self.useFixture).
 
29
        self.addCleanup(self._gather_details, fixture.getDetails)
 
30
 
 
31
        with fixture:
30
32
            # We can connect.
31
 
            host = 'localhost:%s' % fixture.config.port
32
 
            conn = amqp.Connection(host=host, userid="guest",
33
 
                password="guest", virtual_host="/", insist=False)
34
 
            conn.close()
35
 
            # And get a log file
36
 
            log = fixture.getDetails()['rabbit log file']
 
33
            connect_arguments = {
 
34
                "host": 'localhost:%s' % fixture.config.port,
 
35
                "userid": "guest", "password": "guest",
 
36
                "virtual_host": "/", "insist": False,
 
37
                }
 
38
            amqp.Connection(**connect_arguments).close()
 
39
            # And get a log file.
 
40
            log = fixture.runner.getDetails()["rabbit.log"]
37
41
            # Which shouldn't blow up on iteration.
38
42
            list(log.iter_text())
39
 
        finally:
40
 
            fixture.cleanUp()
 
43
 
41
44
        # The daemon should be closed now.
42
 
        self.assertRaises(socket.error, amqp.Connection, host=host,
43
 
            userid="guest", password="guest", virtual_host="/", insist=False)
 
45
        self.assertRaises(socket.error, amqp.Connection, **connect_arguments)