Merge lp:~free.ekanayaka/txlongpoll/fast-rabbit-reset into lp:txlongpoll

Proposed by Free Ekanayaka
Status: Merged
Merged at revision: 90
Proposed branch: lp:~free.ekanayaka/txlongpoll/fast-rabbit-reset
Merge into: lp:txlongpoll
Diff against target: 145 lines (+51/-15)
6 files modified
.testr.conf (+1/-2)
README (+1/-1)
buildout.cfg (+6/-0)
txlongpoll/testing/client.py (+25/-10)
txlongpoll/tests/__init__.py (+13/-0)
txlongpoll/tests/test_frontend.py (+5/-2)
To merge this branch: bzr merge lp:~free.ekanayaka/txlongpoll/fast-rabbit-reset
Reviewer Review Type Date Requested Status
William Grant code Needs Fixing
Robert Collins (community) Needs Fixing
Review via email: mp+278287@code.launchpad.net

Description of the change

This branch adds a few improvements to the test suite:

- Take advantage of testresources.OptimisingTestSuite in order to avoid a wholesale shutdown/restart of the rabbit process at each test and just delete the queues created by the test instead.

- Silence the Twisted logger in FrontEndAjaxTest.test_render_error.

- Remove the workaround of aborting tearDown early without running any asynchronous logic (see the comment in the code).

- Point buildout to bson 0.4.3 since the default (1.1.1) is not compatible
with Python 2.

To post a comment you must log in.
90. By Free Ekanayaka

Add custom test program

91. By Free Ekanayaka

Revert spurious changes

Revision history for this message
Robert Collins (lifeless) wrote :

The whole custom runner is not needed, is it? Why is it there. Surely a load_tests hook is much cleaner.

review: Needs Fixing
92. By Free Ekanayaka

Use load_tests protocol

93. By Free Ekanayaka

Fix buildout versions

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

> The whole custom runner is not needed, is it? Why is it there. Surely a
> load_tests hook is much cleaner.

Nice, didn't know about it. Fixed as suggested.

Revision history for this message
Robert Collins (lifeless) :
Revision history for this message
Free Ekanayaka (free.ekanayaka) :
Revision history for this message
William Grant (wgrant) :
review: Approve (code)
Revision history for this message
William Grant (wgrant) wrote :

The new load_tests doesn't seem to work as intended (on at least precise and xenial). If I break at the end and inspect result:

(Pdb) p result
<testresources.OptimisingTestSuite tests=[<unittest2.suite.TestSuite tests=[<unittest2.suite.TestSuite tests=[<txlongpoll.tests.test_client.AMQClosingTest.test_catch_closed [...]

It's an OptimisingTestSuite wrapping a whole lot of normal TestSuites, so the fixture is restarted for each test, and the newly un-neutered tearDown fails.

Overriding loader.suiteClass works, but I wonder if there is a better way.

review: Needs Fixing (code)
94. By Free Ekanayaka

Fix testr configuration

Revision history for this message
William Grant (wgrant) wrote :

As discussed on IRC, the problem was my old version of testresources. Newer versions of OptimisingTestSuite flatten nested test suites, fixing the problem.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.testr.conf'
--- .testr.conf 2011-11-08 11:30:22 +0000
+++ .testr.conf 2016-05-25 08:37:19 +0000
@@ -1,5 +1,4 @@
1[DEFAULT]1[DEFAULT]
2test_command = bin/testpy -m subunit/run -- discover $LISTOPT $IDOPTION2test_command = bin/testpy -m subunit/run -- discover $LISTOPT $IDOPTION
3test_id_option = --load-list $IDFILE3test_id_option = --load-list $IDFILE
4# The "ignore" value below works around a bug in subunit.4test_list_option = --list
5test_list_option = --list=ignore
65
=== modified file 'README'
--- README 2011-11-08 11:30:22 +0000
+++ README 2016-05-25 08:37:19 +0000
@@ -42,7 +42,7 @@
42will build all the test-related parts of txlongpoll and then do a full42will build all the test-related parts of txlongpoll and then do a full
43test run, but43test run, but
4444
45 $ make bin/test45 $ make bin/testpy
4646
47will just do the first part.47will just do the first part.
4848
4949
=== modified file 'buildout.cfg'
--- buildout.cfg 2012-03-12 17:07:58 +0000
+++ buildout.cfg 2016-05-25 08:37:19 +0000
@@ -18,6 +18,12 @@
18# Once you have the desired software, reenable this option.18# Once you have the desired software, reenable this option.
19install-from-cache = true19install-from-cache = true
2020
21[versions]
22# Set the version explicitely for bson, since the default would be
23# version 1.1.1 which is not compatible with Python 2.
24# See https://pypi.python.org/pypi/bson/1.1.0
25bson = 0.4.3
26
21[runtime]27[runtime]
22recipe = zc.recipe.egg:scripts28recipe = zc.recipe.egg:scripts
23eggs = txlongpoll29eggs = txlongpoll
2430
=== modified file 'txlongpoll/testing/client.py'
--- txlongpoll/testing/client.py 2011-09-30 09:56:12 +0000
+++ txlongpoll/testing/client.py 2016-05-25 08:37:19 +0000
@@ -36,12 +36,22 @@
36 return self._real_queue_get(timeout)36 return self._real_queue_get(timeout)
3737
3838
39class RabbitServerWithoutReset(RabbitServer):
40
41 def reset(self):
42 """No-op reset.
43
44 Logic to cleanup relevant state is delegated to the test case, which is
45 in charge to delete the queues it created (see AMQTest.tearDown).
46 """
47
48
39class AMQTest(ResourcedTestCase, TestCase):49class AMQTest(ResourcedTestCase, TestCase):
4050
41 run_tests_with = AsynchronousDeferredRunTestForBrokenTwisted.make_factory(51 run_tests_with = AsynchronousDeferredRunTestForBrokenTwisted.make_factory(
42 timeout=5)52 timeout=5)
4353
44 resources = [('rabbit', FixtureResource(RabbitServer()))]54 resources = [('rabbit', FixtureResource(RabbitServerWithoutReset()))]
4555
46 VHOST = "/"56 VHOST = "/"
47 USER = "guest"57 USER = "guest"
@@ -65,18 +75,23 @@
65 self.factory)75 self.factory)
66 return self.connected_deferred76 return self.connected_deferred
6777
78 def tearDown(self):
79 # The AsynchronousDeferredRunTest machinery from testools doesn't play
80 # well with an asynchronous tearDown decorated with inlineCallbacks,
81 # because testtools.TestCase._run_teardown attempts to ensure that the
82 # test class upcalls testtools.TestCase.tearDown and raises an error if
83 # it doesn't find it. To workaround that, we move the inlineCallbacks
84 # logic in a separate method, so we can run the superclass tearDown()
85 # before returning.
86 deferred = self._deleteQueuesAndExchanges()
87 super(AMQTest, self).tearDown()
88 return deferred
89
68 @inlineCallbacks90 @inlineCallbacks
69 def tearDown(self):91 def _deleteQueuesAndExchanges(self):
70 # XXX: Moving this up here to silence a nigh-on inexplicable error92 """Delete any queue or exchange that the test might have created."""
71 # that occurs when it's at the bottom of the function.
72 self.factory.stopTrying()93 self.factory.stopTrying()
73 self.connector.disconnect()94 self.connector.disconnect()
74 super(AMQTest, self).tearDown()
75
76 # XXX: This is only safe because we tear down the whole server.
77 # We can't run this after the tearDown above, because the
78 # fixture is gone.
79 return
8095
81 self.connected_deferred = Deferred()96 self.connected_deferred = Deferred()
82 factory = AMQFactory(self.USER, self.PASSWORD, self.VHOST,97 factory = AMQFactory(self.USER, self.PASSWORD, self.VHOST,
8398
=== modified file 'txlongpoll/tests/__init__.py'
--- txlongpoll/tests/__init__.py 2011-06-28 16:21:03 +0000
+++ txlongpoll/tests/__init__.py 2016-05-25 08:37:19 +0000
@@ -1,2 +1,15 @@
1# Copyright 2005-2011 Canonical Ltd. This software is licensed under the1# Copyright 2005-2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
3import os
4
5from testresources import OptimisingTestSuite
6
7
8def load_tests(loader, standard_tests, pattern):
9 # top level directory cached on loader instance
10 this_dir = os.path.dirname(__file__)
11 package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
12 result = OptimisingTestSuite()
13 result.addTests(standard_tests)
14 result.addTests(package_tests)
15 return result
316
=== modified file 'txlongpoll/tests/test_frontend.py'
--- txlongpoll/tests/test_frontend.py 2011-09-30 09:56:12 +0000
+++ txlongpoll/tests/test_frontend.py 2016-05-25 08:37:19 +0000
@@ -6,7 +6,10 @@
6from unittest import defaultTestLoader6from unittest import defaultTestLoader
77
8from testtools import TestCase8from testtools import TestCase
9from testtools.deferredruntest import assert_fails_with9from testtools.deferredruntest import (
10 assert_fails_with,
11 run_with_log_observers,
12 )
10from twisted.internet import reactor13from twisted.internet import reactor
11from twisted.internet.defer import (14from twisted.internet.defer import (
12 Deferred,15 Deferred,
@@ -374,7 +377,7 @@
374 """377 """
375 self.message_queue.messages["uuid1"] = ValueError("Not there")378 self.message_queue.messages["uuid1"] = ValueError("Not there")
376 request = FakeRequest({"uuid": ["uuid1"], "sequence": ["0"]})379 request = FakeRequest({"uuid": ["uuid1"], "sequence": ["0"]})
377 self.ajax.render(request)380 run_with_log_observers([], self.ajax.render, request)
378 self.assertEquals(request.written.getvalue(), "Not there")381 self.assertEquals(request.written.getvalue(), "Not there")
379 self.assertEquals(request.code, 500)382 self.assertEquals(request.code, 500)
380383

Subscribers

People subscribed via source and target branches